Al *_*azi 1 javascript jquery json
好的,我有一个json输出,如下所示:
{"Result" : [
{
"Id" : "5214",
"ParentReasonId" : "0",
"Description" : "Billing & Payment",
"SysName" : "Billing & Payment",
"SysCategory" : "Billing & Payment",
"ClientId" : "924",
"DispositionCount" : "6",
"IsActive" : true,
"ChildReasonCount" : "8",
"Attributes" : [],
"SortOrder" : "0",
"CreatedBy" : null
}
]
}
Run Code Online (Sandbox Code Playgroud)
我想从中提取id和描述的数据.
jQuery("#chained_child").cascade("#chained", {
ajax: { url: 'Customhandler.ashx?List=MyList' },
template: commonTemplate,
match: commonMatch
});
function commonTemplate(item) {
return "<option Value='" + item.Result.Id + "'>"
+ item.Result.Description + "</option>";
};
Run Code Online (Sandbox Code Playgroud)
但对于我的生活,我无法让它回报我正在寻找的价值.我知道这是一些蠢货,但我正在撞墙.有人可以帮忙吗?
如果检查JSON字符串,则Result对象实际上是一个大小为1的数组,其中包含一个对象,而不仅仅是一个对象.您应该删除额外的括号或使用以下内容引用您的变量:
item.Result[0].Id
Run Code Online (Sandbox Code Playgroud)
要使用item.Result.Id您的变量引用,您需要以下JSON字符串:
{
"Result" :
{
"Id" : "5214",
"ParentReasonId" : "0",
"Description" : "Billing & Payment",
"SysName" : "Billing & Payment",
"SysCategory" : "Billing & Payment",
"ClientId" : "924",
"DispositionCount" : "6",
"IsActive" : true,
"ChildReasonCount" : "8",
"Attributes" : [],
"SortOrder" : "0",
"CreatedBy" : null
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1159 次 |
| 最近记录: |