0

I'm trying to use PHP to process JSON and am having trouble parsing it as either an object or a string. Here is the JSON feed:

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 ) ) ) ) ) ) 

Obviously, I can also access it as an array. Either way, however, I can't actually parse it. I have tried, for example:

$json->Response->Data->Entity->id;

or for arrays:

$json['Response']['Data']['Entity']['id'];

Neither of these works. For objects, I'm told "Trying to get property of non-object" and for strings nothing displays.

I'm more used to dealing with JSON in Python, and json['Response']['Data']['Entity']['id'] works just fine in Python but I need to do this in PHP. I'm sure I'm doing something very obvious, but can't puzzle through it.

asked Oct 12, 2010 at 1:23

1 Answer 1

1

Use json_decode() on the JSON string first and then php can parse it as an array.

answered Oct 12, 2010 at 1:30
Sign up to request clarification or add additional context in comments.

1 Comment

I was just about to say that of course I had already done that when I double-checked my code and realized that I hadn't assigned the decoded variable. So, feeling pretty ridiculous, but thanks for getting me there.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.