【发布时间】:2010-12-06 18:21:08
【问题描述】:
我正在努力使用 PHP 解析以下数据。 API 返回它,我尝试了各种语法。如何以非对象方式返回数据?或者,使用 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"
}
}
}
【问题讨论】:
-
这个对象来自哪里?
-
来自这个 API,emmense.com/sunlight-labs-php-library api_key = '[api 密钥]';回声'
'; print_r($sf->districtsByZipCode(14485));回声'
'; ?>