$(document).ready(function(){
var json = JSON.parse("[{"pieDataList":
[{"value":100,"key":"non"}],
"titre":"fghjklcom","nbreReponse":1},{"pieDataList":
[{"value":100,"key":"non"}],
"titre":"fghjklcom","nbreReponse":1}]");
// $.each(json, function (index,ch) {
for(i in json) {
var value=[];
//get the map
for(j=0;j<json[i].PieDataList.length;j++) {
//iterate each item of list
value.push([json[i].PieDataList[j].key,
json[i].PieDataList[j].value]);
}
var plot1 = jQuery.jqplot ('ch', [value],
{
seriesDefaults: {
// Make this a pie chart.
renderer: jQuery.jqplot.PieRenderer,
rendererOptions: {
// Put data labels on the pie slices.
// By default, labels show the percentage of the
slice.
showDataLabels: true
}
},
legend: { show:true, location: 'e' }
})}
alert(item.PieDataList);
console.log("Titre="+item.Titre);
});
答案 0 :(得分:0)
一开始的JSON不能只是粘贴到代码中。它是一个字符串,但是有换行符的换行符和双引号字符也会结束字符串。
您只需将JSON粘贴为变量而不是字符串,JavaScript就可以正常使用:
var json = [{"pieDataList":
[{"value":100,"key":"non"}],
"titre":"fghjklcom","nbreReponse":1},{"pieDataList":
[{"value":100,"key":"non"}],
"titre":"fghjklcom","nbreReponse":1}];