【发布时间】:2020-02-09 15:46:28
【问题描述】:
我有以下 php 代码:
echo(json_encode(array('msg'=>'7','result'=>$list)));
它使用ajax返回以下json:
msg 7
result […]
0 {…}
0 2
1 Family, Release
2 test 2 v/s test 3
3 this is the test for judgment file 2
4 null
5 2019-10-10 10:10 PM
6 1
7 null
8 1
sno 2
keywords Family, Release
case_title test 2 v/s test 3
law this is the test for judgment file 2
judgment_file null
added_on 2019-10-10 10:10 PM
added_by 1
user_ip null
is_confirmed 1
1 {…}
0 3
1 Family
2 Test 3 V/S Test 4
3 this is tthird record
4 null
5 2019-10-10 10:10 PM
6 1
7 null
8 1
sno 3
keywords Family
case_title Test 3 V/S Test 4
law this is tthird record
judgment_file null
added_on 2019-10-10 10:10 PM
added_by 1
user_ip null
is_confirmed 1
问题 1:它返回单行结果两次,即使用 0,1,...8 而使用表字段名称,即 sno = 2 个关键字 = xxx
我需要为每一行获取单个结果。
问题2:如何使用JavaScript/jQuery从json中获取所有字段?
【问题讨论】:
-
$list 已经是 json 了吗?另外,您能否格式化输出更多。使用
console.log("%j", jsonObj);或console.log(JSON.stringify(data))在控制台打印格式化数据。