我有这样的数据
{
"tanggal":"2015-05-31",
"idSupplier":"15",
"totalBeli":1680000,
"dataBarang":[
{
"kode":"111",
"nama":"asus",
"jenisid":"1",
"jenisnama":"Flashdisk",
"hargasatuan":"90000",
"hargajual":"120000",
"jumlahstok":"12",
"stockmin":"10",
"satuan":"unit"
},
{
"kode":"124",
"nama":"cliptec",
"jenisid":"1",
"jenisnama":"Flashdisk",
"hargasatuan":"50000",
"hargajual":"100000",
"jumlahstok":"12",
"stockmin":"2",
"satuan":"unit"
}
]
}
以及如何使用PHP获取对象中的值数组 例如,我需要来自对象dataBarang
的值之前感谢
答案 0 :(得分:0)
解码你的json数组,然后使用以下代码获取值:
$jsonArr = json_decode($json);
echo '<pre>';print_r($jsonArr);echo '</pre>';
// To fetch object
echo '<pre>';print_r($jsonArr->dataBarang);echo '</pre>';
// To fetch single array from object
echo '<pre>';print_r($jsonArr->dataBarang[0]);echo '</pre>';
// To Array -> object -> array -> object by array key
echo '<pre>';print_r($jsonArr->dataBarang[0]->kode);echo '</pre>';