0

I have a piece of JSON that I'm parsing with php. I need to get one of the pieces of data out of it.

Here's the output of the json when I do a print_r:

Array ( [deviceId] => 07a9727e-3fe5-4f44-9765-134388241f39 [programId] => 3895 [serviceId] => 19977 [createdAt] => 2013-12-12T07:19:04.466Z [updatedAt] => 2013-12-12T07:19:04.466Z [objectId] => 7TxmL2GiXq )

Here's my code trying to extract deviceId:

$objectData = json_decode($data, true);
print_r($objectData);
$deviceId = $objectData->deviceId;

$deviceId is coming back empty.

Any help would be appreciated. Thanks.

0

1 Answer 1

4

Do this:

$deviceId = $objectData['deviceId'];

You are using the optional second parameter TRUE in your json_decode call, which converts it into an associative array instead of an object.

Alternatively:

$objectData = json_decode($data);
$deviceId = $objectData->deviceId; // Works
Sign up to request clarification or add additional context in comments.

1 Comment

awesome! this works! I knew it was something small I was overlooking. Thanks so much.

Your Answer

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.