小编sam*_*her的帖子

在jQuery AJAX post输出中读取JSON数据

我有下面的代码,我通过json传递给jquery.

$string['msg']['1']['Name'] = "John Doe";
$string['msg']['1']['Said'] = "Hello there";

$string['msg']['2']['Name'] = "Jane King";
$string['msg']['2']['Said'] = "Hello there";

$string['errors']['1']['Person'] = "Jane King";
$string['errors']['1']['type'] = "Wrong Screwdriver";


$string['errors']['2']['Person'] = "John Doe";
$string['errors']['2']['type'] = "Wrong Spanner";
Run Code Online (Sandbox Code Playgroud)

JSON输出如下:

{"msg":{"1":{"Name":"John Doe","Said":"Hello there"},"2":{"Name":"Jane King","Said":"Hello there"}},"errors":{"1":{"Person":"Jane King","type":"Wrong Screwdriver"},"2":{"Person":"John Doe","type":"Wrong Spanner"}}}
Run Code Online (Sandbox Code Playgroud)

这是正在检索json的ajax代码.

$.ajax({
    dataType : 'json',
    url: 'polling.php',
    type: 'post',
    data: 'id=1',
    success: function(data) {
        //read json     

});
Run Code Online (Sandbox Code Playgroud)

我试图按照数字顺序读取所有'msg'.. 1,2 ..并获得每个的'Name'和'Said'值.

然后为'错误'做同样的事情

但我无法正确检索任何值

javascript arrays ajax jquery json

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

ajax ×1

arrays ×1

javascript ×1

jquery ×1

json ×1