R
R
root092016-03-02 21:43:25
PHP
root09, 2016-03-02 21:43:25

How to extract value from json?

I have a json like this:

{"success":true,"inventory":{"5308188287":{"id":"5308188287","classid":"1483678044"},"5308188011":{"id":"5308188011","classid":"720640649"},"5308154952":{"id":"5308154952","classid":"311939473"}}}

how to get the classid value of an element with id 5308188287 using php?
Now I do like this:
$json_decoded = json_decode($page);
foreach ($json_decoded->inventory as $item)
{
    if ($item->id == 5308188287)
      ....
}

Is it possible to immediately access the element with id 5308188287 without iterating through the loop?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2016-03-02
@root09

$json_decoded->inventory->{5308188287}->classid
ideone.com/4Sbe0j

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question