如果这:
{
"order": {
"Food": "[Test 1, Test 2, Test 0, Test 3, Test 1, Test 3, Test 11, Test 7, Test 9, Test 8, Test 2]",
"Quantity": "[2, 3, 6, 2, 1, 7, 10, 2, 0, 0, 1]"
},
"tag": "neworder"
}
确实是您正在使用的 json,那么您将不得不做一些工作来获得您想要的东西。
$obj = json_decode($json);
// the food and quantity properties are string not json.
$foods = explode("," trim($obj->order->Food;, "[]"));
$foods = array_map("trim", $foods); // get rid of the extra spaces
$quantitys = json_decode($obj->order->Quantity);
要使它成为有效的 json,它必须像这样编写
{
"order": {
"Food": ["Test 1", "Test 2", "Test 0", "Test 3", "Test 1", "Test 3", "Test 11", "Test 7", "Test 9", "Test 8", "Test 2"],
"Quantity": [2, 3, 6, 2, 1, 7, 10, 2, 0, 0, 1]
},
"tag": "neworder"
}