如何从json字符串中获取键值

时间:2014-07-01 07:19:56

标签: javascript html ajax json

我有像json的回应

{
    [{
        "name": "abc.html",
        "size": 28135,
        "type": "text/html",
        "delete_url": "XXX",
        "delete_type": "DELETE",
        "attachmentFilePath": "attachment_53b2608e40100/abc.html"
    }, {
        "name": "def.html",
        "size": 10465,
        "type": "text/html",
        "delete_url": "XXXXXX",
        "delete_type": "DELETE",
        "attachmentFilePath": "attachment_53b2608e42bd8/def.html"
    }]
}

我从obj.toString()获得。

我想提醒每个键/值,例如name:abc.htmlsize:28135

1 个答案:

答案 0 :(得分:1)

试试这段代码:

obj.forEach(function (d) {    
  alert('name: ' + d.name + ' size: ' + d.size;    
});

希望这有帮助。