2016-01-03 34 views
2

从php脚本中检索到以下JSON数据,现在我想解析这个JSON数据。请有人帮我解析这个JSON数据。如何在jquery ajax成功函数中解析以下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

使用'值“AVG(Q1)”]' –

+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>

+0

u能帮助我这个JSON包含空值我想删除它如何才能做到这一点,我的意思是包含json空值的整个对象 –

+0

欢迎@SagarYadav –