我有这个JSON格式的多维数组。
{
"CUSTOMER_ORDER":
[
{
"customer_number": "51",
"table_no": "7",
"menu_name": "Fried Chicken",
"menu_quatity": "5",
"menu_price": "200",
"order_total_price": "1000"
},
{
"customer_number": "51",
"table_no": "7",
"menu_name": "Fries",
"menu_quatity": "5",
"menu_price": "200",
"order_total_price": "1000"
}
]
}
我的问题是我如何获取CUSTOMER_ORDER
的索引0上的特定数据?
例如,我想得到一个menu_name
的{{1}},谢谢。
更新
解码JSON数据后遇到麻烦,我得到的是这样:
Fried Chicken
当我使用这个时:
json_decode() expects parameter 1 to be string, array given
当我尝试此操作时:
$json_data = $this->post('CUSTOMER_ORDER');
$json_decoded = json_decode($json_data);
$customer_nickname = $json_decoded->CUSTOMER_ORDER[0]->customer_nickname;
通过我使用CodeIgniter 3的方式,希望有人帮助我。谢谢。
答案 0 :(得分:1)
希望对您有帮助。
$json = '{
"CUSTOMER_ORDER":
[
{
"customer_number": "51",
"table_no": "7",
"menu_name": "Fried Chicken",
"menu_quatity": "5",
"menu_price": "200",
"order_total_price": "1000"
},
{
"customer_number": "51",
"table_no": "7",
"menu_name": "Fries",
"menu_quatity": "5",
"menu_price": "200",
"order_total_price": "1000"
}
]
}';
$jsonDecodedArray = json_decode($json);
print_r($jsonDecodedArray->CUSTOMER_ORDER[0]->customer_number);
// OUTPUT 51