2016-01-03 56 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 –