我有一個JSON數組像吹:如何解析這種JSON數組的
{
"0": {
"kind": "mammal",
"name": "Pussy the Cat",
"weight": "12kg",
"age": "5"
},
"1": {
"kind": "mammal",
"name": "Roxy the Dog",
"weight": "25kg",
"age": "8"
},
"2": {
"kind": "fish",
"name": "Piranha the Fish",
"weight": "1kg",
"age": "1"
},
"3": {
"kind": "bird",
"name": "Einstein the Parrot",
"weight": "0.5kg",
"age": "4"
}
}
我刪除的元素「食人魚魚」隨着(未設置)我的JSON代碼改變吹:
{
"0": {
"kind": "mammal",
"name": "Pussy the Cat",
"weight": "12kg",
"age": "5"
},
"1": {
"kind": "mammal",
"name": "Roxy the Dog",
"weight": "25kg",
"age": "8"
},
"3": {
"kind": "bird",
"name": "Einstein the Parrot",
"weight": "0.5kg",
"age": "4"
}
}
當我刪除元素的元素變化的計數器0,1,3 所以現在我不能在我的JSON元素完全訪問
我想這個代碼回聲值:
for ($i = 0; $i < $JsonCount - 1; $i++) {
echo "Name :";
echo $json_cod[$i]['name'];
echo "<br/>";
echo "Age :";
echo $json_cod[$i]['age'];
echo "<br/>";
}
出認沽:
Name :Pussy the Cat
Age :5
Name :Roxy the Dog
Age :8
http://php.net/manual/en/control-structures.foreach.php – wazelin
你的數據結構看起來並不像一個JSON陣列。你確定這就是你想要解析的嗎? –
http://php.net/manual/en/function.array-values.php –