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

Javascript 如何从json字符串中获取键值,javascript,html,ajax,json,Javascript,Html,Ajax,Json,我有类似的json响应 { [{ "name": "abc.html", "size": 28135, "type": "text/html", "delete_url": "XXX", "delete_type": "DELETE", "attachmentFilePath": "attachment_53b2608e40100/abc.html" }, { "nam

我有类似的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.html
size:28135

尝试以下代码:

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

希望这有帮助。

为什么要使用
obj.toString
来字符串化对象?如果您已经有了一个对象,为什么不迭代它并输出您需要的内容呢?这是无效的JSON。尝试在jsonlint中验证响应。org@AlokSwain:它是一个完全有效的JavaScript对象。@Cerbrus OP应该删除
JSON
标记。@Cerbrus但这不是有效的JSON对象