gpt4 book ai didi

jquery - 如何在jquery ajax成功函数中解析以下json

转载 作者:行者123 更新时间:2023-12-01 04:03:40 25 4
gpt4 key购买 nike

以下 JSON 数据从 php 脚本检索,现在我想解析此 JSON 数据。请有人帮我解析这个 JSON 数据。

[{
"0": "1.0000",
"AVG(Q1)": "1.0000",
"1": "1.8000",
"AVG(Q2)": "1.8000",
"2": "2.0000",
"AVG(Q3)": "2.0000",
"3": "2.4000",
"AVG(Q4)": "2.4000",
"4": "1.6000",
"AVG(Q5)": "1.6000",
"5": "1.2000",
"AVG(Q6)": "1.2000",
"6": "2.0000",
"AVG(Q7)": "2.0000",
"7": "2.4000",
"AVG(Q8)": "2.4000",
"8": "0.8000",
"AVG(Q9)": "0.8000",
"9": "2.8000",
"AVG(Q10)": "2.8000",
"10": "1.8000",
"AVG(Q11)": "1.8000"
}, {
"0": null,
"AVG(Q1)": null,
"1": null,
"AVG(Q2)": null,
"2": null,
"AVG(Q3)": null,
"3": null,
"AVG(Q4)": null,
"4": null,
"AVG(Q5)": null,
"5": null,
"AVG(Q6)": null,
"6": null,
"AVG(Q7)": null,
"7": null,
"AVG(Q8)": null,
"8": null,
"AVG(Q9)": null,
"9": null,
"AVG(Q10)": null,
"10": null,
"AVG(Q11)": null
}]

我尝试了不同的方法来解析这个 JSON,但所有方法都失败了。请帮我解析这个 JSON。

我尝试了此操作,但表格元素中没有显示任何值:

var obj = jQuery.parseJSON(data);
$.each(obj, function(key, value){
$('table').append('<tr><td>'+value.avg(q1)+'</td></tr>');
});

最佳答案

请检查代码段。无需解析json

var jsobObj = [{
"0": "1.0000",
"AVG(Q1)": "1.0000",
"1": "1.8000",
"AVG(Q2)": "1.8000",
"2": "2.0000",
"AVG(Q3)": "2.0000",
"3": "2.4000",
"AVG(Q4)": "2.4000",
"4": "1.6000",
"AVG(Q5)": "1.6000",
"5": "1.2000",
"AVG(Q6)": "1.2000",
"6": "2.0000",
"AVG(Q7)": "2.0000",
"7": "2.4000",
"AVG(Q8)": "2.4000",
"8": "0.8000",
"AVG(Q9)": "0.8000",
"9": "2.8000",
"AVG(Q10)": "2.8000",
"10": "1.8000",
"AVG(Q11)": "1.8000"
}, {
"0": null,
"AVG(Q1)": null,
"1": null,
"AVG(Q2)": null,
"2": null,
"AVG(Q3)": null,
"3": null,
"AVG(Q4)": null,
"4": null,
"AVG(Q5)": null,
"5": null,
"AVG(Q6)": null,
"6": null,
"AVG(Q7)": null,
"7": null,
"AVG(Q8)": null,
"8": null,
"AVG(Q9)": null,
"9": null,
"AVG(Q10)": null,
"10": null,
"AVG(Q11)": null
}];


$.each(jsobObj, function(key, value){
$('table').append('<tr><td>'+(value["AVG(Q1)"]==null?"":value["AVG(Q1)"])+'</td></tr>');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
</table>

关于jquery - 如何在jquery ajax成功函数中解析以下json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34574764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com