我有一个PHP脚本和JSON对象,其中一些值正在PHP get函数中传递。我尝试过不同的方法解码JSON但失败了。 我试过的代码是:
$get_order_info = $_GET['orderInfo'];
$order_json = json_decode($get_order_info, true);
echo $order_json->{'mealsInfo'};
JSON字符串是:
{
"mealsInfo" : [
{
"DrinkSize" : 1,
"MealQuantity" : 1,
"MealId" : "57",
"addons" : [
{
"addOnID" : 1,
"addonTitle" : "spicy"
},
{
"addOnID" : 3,
"addonTitle" : "Thin Base"
}
],
"FriesSize" : 2
}
],
"TransactionID" : "56",
"OrerType" : "PickUp",
"frenchiseInfo" : {
"storeName" : "Dubai Downtown Franchise",
"OrderCollectionTime" : "06:12:50 PM",
"FranchiseId" : "4"
},
"customerinfo" : {
"Instructions" : "Test instruction",
"CustomerName’" : "Talat",
"Area" : "al Riga",
"City" : "Dubai",
"Phone" : "0559467800",
"Email" : "test@test.com",
"Address" : "al nouf tower"
},
"status" : "pending",
"totalPrice" : 51
}
有人可以帮我解决一下吗? 提前谢谢!
答案 0 :(得分:1)
您将true
作为第二个参数传递给json_decode
,它将返回并且数组不是对象。试试 -
$order_json = json_decode($get_order_info, true);
echo $order_json['mealsInfo'][0]['DrinkSize'];
答案 1 :(得分:0)
$get_order_info = $_POST['orderInfo'];
$order_json = json_decode($get_order_info, true);
echo $order_json->{'mealsInfo'};
答案 2 :(得分:0)
试试这个。
$order_json = json_decode($get_order_info, true);
var_dump($order_json->{'mealsInfo'});