我有一个 json 字符串
[{"part_id":"66","part_name":"Palet crate","part_image":"crate-box.gif","0":{"language_data_content":"Length [mm]","pgd_value":"1000"},"1":{"language_data_content":"Width [mm]","pgd_value":"800"},"2":{"language_data_content":"Height [mm]","pgd_value":"800"},"3":{"language_data_content":"Thickness [mm]","pgd_value":"20"}}]
这是我在控制器中的操作的 Ajax 响应的一部分
for($i=0;$i<count($partlist);$i++){
$jsondata[$i]['part_id'] = $partlist[$i]['part_id'];
$jsondata[$i]['part_name'] = $partlist[$i]['part_name'];
$jsondata[$i]['part_image'] = $partlist[$i]['part_image'];
$gdata = $pgdata->getPropertyDimensions($partlist[$i]['part_id'],1);
if(count($gdata) > 0){
$j = 0;
foreach($gdata as $g){
$jsondata[$i][$j]['language_data_content'] = $g->language_data_content;
$jsondata[$i][$j]['pgd_value'] = $g->pgd_value;
$j++;
}
}
}
echo json_encode($jsondata);exit;
对于一个部分 id 可以有多个pgd_value在这个 json 数组中只有一个部分 id 和四个pgd_value ..在我的 ajax 成功函数中循环这个 json 为
success:function(msg){
str = '';
if(msg.length > 0){
for(j=0;j<msg.length;j++){
str +='<span>'+msg[j]['part_id']+'</span>';
// here i want to loop those four **pgd_value** values from json is it possible ?
}
}
}