这是我的json格式
({"message":{"success":true,"result":[{"lead_no":"LEA13","lastname":"Developer","firstname":"PHP","company":"Dummies","email":"nandhajj@gmail.com","id":"10x132"},{"lead_no":"LEA14","lastname":"Venu","firstname":"Yatagiri","company":"Rsalesarm","email":"veve@jajs.com","id":"10x133"},{"lead_no":"LEA4","lastname":"Jones","firstname":"Barbara","company":"Vtigercrm inc","email":"barbara_jones@company.com","id":"10x35"},{"lead_no":"LEA1","lastname":"Smith","firstname":"Mary","company":"Vtiger","email":"mary_smith@company.com","id":"10x32"}]}})
我正在尝试使用以下代码段检索整个json结果值
if (xmlHttp.readyState==4)
{
alert(xmlHttp.status);
if(xmlHttp.status==200)
{
alert("hi");
var jsondata=eval("("+xmlHttp.responseText+")") //retrieve result as an JavaScript object
jsonOutput=jsondata.result;
alert(jsonOutput);
InitializeLeadStorage()
}
}
我的alert (hi )
已显示,但alert(jsonOutput);
未定义,如果您发现任何错误,请帮助我
答案 0 :(得分:0)
jsonOutput = jsondata.message.result;
result
位于message
- 它不是JSON中的顶级项目。通过这样的事情,console.log()
JSON,您可以检查所需位的路径。
另外
JSON.parse()
,否则使用jQuery或其他第三方实用程序