JSON解析不能在asp .net中工作

时间:2014-11-02 08:07:32

标签: javascript json

这是我的json数据     enter image description here

使用var data = JSON.parse(value);解析后,显示:

enter image description here

我无法理解,这里的json解析有什么问题?

1 个答案:

答案 0 :(得分:0)

确实可行。
你有一个array of objects

var data = JSON.parse(value); // array of objects
var firstObj = data[0];
console.log(firstObj.ItemId); // 153

这是另一个例子:

var jsonStr = '[{"ItemId":157, "Details":"first item"},{"ItemId":158, "Details":"second item"}]';
var json = JSON.parse(jsonStr);
console.log(json); // [Object, Object] 
for(var i = 0 ; i < json.length; i++)
{
    // Object {ItemId: 157, Details: "first item"} 
    // Object {ItemId: 158, Details: "second item"} 
    console.log(json[i]);

    //157 
    //158
    console.log(json[i].ItemId);
}

JSFIDDLE