【发布时间】:2026-01-27 10:35:01
【问题描述】:
我正在尝试使用 PHP 来处理 JSON,但无法将其解析为对象或字符串。这是 JSON 提要:
stdClass Object ( [Response] => stdClass Object ( [Meta] => stdClass Object ( [ExecutionTime] => 0.41602396965 ) [Data] => stdClass Object ( [Entity] => stdClass Object ( [id] => 1 [name] => Wal-Mart Stores [description] => Retail merchandising [summary] => [start_date] => [end_date] => [is_current] => 1 [primary_type] => Org [parent_id] => [updated_at] => 2010-09-27 11:11:55 [uri] => http://littlesis.org/org/1/Wal-Mart_Stores [api_uri] => http://api.littlesis.org/entity/1.xml [types] => Org,Business,PublicCompany [name_nick] => [employees] => [revenue] => 378799000000 [fedspending_id] => 336092 [lda_registrant_id] => 40305 [annual_profit] => [ticker] => WMT [sec_cik] => 104169 [Aliases] => stdClass Object ( [Alias] => Array ( [0] => Wal Mart [1] => Walmart ) ) ) ) ) )
显然,我也可以将其作为数组访问。但是,无论哪种方式,我实际上都无法解析它。我试过了,例如:
$json->Response->Data->Entity->id;
或者对于数组:
$json['Response']['Data']['Entity']['id'];
这些都不起作用。对于对象,我被告知“尝试获取非对象的属性”,而对于字符串则没有任何显示。
我更习惯于在 Python 中处理 JSON,而 json['Response']['Data']['Entity']['id'] 在 Python 中工作得很好,但我需要在 PHP 中执行此操作.我确定我在做一些非常明显的事情,但无法理解它。
【问题讨论】: