我努力用PHP解析下面的数据。一个API返回它,并且我尝试了各种语法。如何以非对象的方式返回数据?或者,使用stdClass调用数据的语法是什么?stdClass对象问题
我可以将其转换为一个基于数据的数组,甚至两个?谈到基于对象的数据集时,我迷失了方向。
stdClass Object
(
[0] => stdClass Object
(
[district] => stdClass Object
(
[state] => NY
[number] => 29
)
)
[1] => stdClass Object
(
[district] => stdClass Object
(
[state] => NY
[number] => 26
)
)
)
当我创造我自己的对象,然后做的var_dump,我得到这个:
object(stdClass)#8 (2) {
[0]=>
object(stdClass)#4 (1) {
["district"]=>
object(stdClass)#5 (2) {
["state"]=>
string(2) "NY"
["number"]=>
string(2) "29"
}
}
[1]=>
object(stdClass)#6 (1) {
["district"]=>
object(stdClass)#7 (2) {
["state"]=>
string(2) "NY"
["number"]=>
string(2) "26"
}
}
}
此对象来自哪里? – 2009-10-14 17:18:02
从这个API中,http://emmense.com/sunlight-labs-php-library/ <?php include('class.sunlightlabs.php'); $ sf = new SunlightDistrict; $ sf-> api_key ='[api key]'; echo'
'; ?> – ader 2009-10-14 17:20:41