【发布时间】:2012-06-15 20:57:00
【问题描述】:
努力将 json 从 URL 上的文件 (myData.json) 加载到对象中,以便我可以访问属性值。
-- 数据立即加载,我在应用程序中非常需要它。
-- 我将访问整个应用程序中的数据,而不仅仅是在数据加载后立即发生的某个函数的一部分。
-- 我已确保我的文件中的数据是正确格式的 json。
按照 jquery API 上的示例,我不应该做一些简单的事情吗:
警报(jqxhr.myProperty);
并获得价值? 我在这里错过了什么步骤?我尝试过运行 eval 和各种类似的东西
var myObj=JSON.parse(jqxhr);
无济于事。
请……谢谢。
// Assign handlers immediately after making the request,
// and remember the jqxhr object for this request
var jqxhr = $.getJSON("example.json", function() {
alert("success");
})
.success(function() { alert("second success"); })
.error(function() { alert("error"); })
.complete(function() { alert("complete"); });
// perform other work here ...
// Set another completion function for the request above
jqxhr.complete(function(){ alert("second complete"); });
【问题讨论】:
标签: javascript jquery json object