从php脚本中检索以下JSON数据,现在我想解析这个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>');
});
答案 0 :(得分:2)
请检查代码段。无需解析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>