【发布时间】:2010-03-25 05:33:52
【问题描述】:
我有一个这样的 JSON 数据:
{
"hello":
{
"first":"firstvalue",
"second":"secondvalue"
},
"hello2":
{
"first2":"firstvalue2",
"second2":"secondvalue2"
}
}
我知道如何从对象 "first" (firstvalue) 和 second (secondvalue) 中检索数据,但我想循环遍历该对象并获取值:"hello" 和 "hello2"...
这是我的 PHP 代码:
<?php
$jsonData='{"hello":{"first":"firstvalue","second":"secondvalue"},"hello2":{"first2":"firstvalue2","second2":"secondvalue2"}}';
$jsonData=stripslashes($jsonData);
$obj = json_decode($jsonData);
echo $obj->{"hello"}->{"first"}; //result: "firstvalue"
?>
可以吗?
【问题讨论】: