我有一个JSON对象没有给出三个值的键(每个都是一个数组),我想解析它们。我怎么能在JQuery中做到这一点?
[
{
"cid": "3",
"pid": "0",
"nid": "12",
"uid": "4",
"subject": "test2",
"hostname": "127.0.0.1",
"created": "1374084646",
"changed": "1374084645",
"status": "1",
"thread": "02/",
"name": "chrisr",
"mail": "",
"homepage": "",
"language": "en",
"uuid": "e4729a69-7f6f-4091-98a0-0a040fe683f1",
},
{
"cid": "2",
"pid": "0",
"nid": "13",
"uid": "4",
"subject": "TEST comment 2",
"hostname": "127.0.0.1",
"created": "1374072245",
"changed": "1374072244",
"status": "1",
"thread": "01/",
"name": "chrisr",
"mail": "",
"homepage": "",
"language": "en",
"uuid": "b4d5a084-8aa3-4828-b6e4-17396cbaf2f6",
},
{
"cid": "1",
"pid": "0",
"nid": "12",
"uid": "4",
"subject": "test comment",
"hostname": "127.0.0.1",
"created": "1374072176",
"changed": "1374072175",
"status": "1",
"thread": "01/",
"name": "chrisr",
"mail": "",
"homepage": "",
"language": "en",
"uuid": "7ade4906-7d6e-4cad-9f97-7f43eadea731",
}
]
答案 0 :(得分:5)
您的JSON无效。
创建有效的JSON字符串后,解析它非常简单。
使用以下步骤:
jQuery.parseJSON()
醇>
它的确是这样的:
var jsonText = '[ { "cid": "3", "pid": "0", "nid"...} ]';
var jo = $.parseJSON(jsonText);
答案 1 :(得分:2)