这是我的JSON数据:
{"Liste_des_produits1":[{"Added_Time":"28-Sep-2009 16:35:03","prod_ingredient":"sgsdgds","prod_danger":["sans danger pour xyz"],"prod_odeur":["Orange"],"prod_nom":"ceciestunproduit","prod_certification":["HE • Haute Efficité","Certifier Ecologo","Contenant recyclable"],"prod_photo":"","prod_categorie":["Corporel"],"prod_desc":"gdsg","prod_format":["10 kg","20 kg"]},{"Added_Time":"28-Sep-2009 16:34:52","prod_ingredient":"dsgdsgdsf","prod_danger":["Sans danger pour le fausse sceptiques"],"prod_odeur":["Agrumes","Canneberge"],"prod_nom":"jsute un test","prod_certification":["100% Éco-technologie","Certifier Ecologo","Contenant recyclable"],"prod_photo":"","prod_categorie":["Corporel"],"prod_desc":"gsdgsdgsdg","prod_format":["1 Litre","10 kg"]}]}
在PHP中,访问不同数据值的方法是什么?
赞:prod_ingredient
或prod_danger
。
我试过了:
$prod = $result->{'Liste_des_produits1'};
print_r($prod[0]); // error
和
$result = json_decode($json);
print_r($result['Liste_des_produits1'].prod_ingredient[1]); // error
答案 0 :(得分:7)
使用json_decode将数据转换为关联数组。
$data = json_decode($jsonString, true);
// extend this concept to access other values
$prod_ingredient = $prod['Liste_des_produits1'][0]['prod_ingredient'];
答案 1 :(得分:0)
然后您可以作为常规数组访问数据。