Anil Sharma
Anil Sharma

Reputation: 2962

get value from JSON string

I have a object as shown below and i want to extract data from

stdClass Object
(
   [day1] => stdClass Object
     (
        [0] => 12.06.2015
        [part1] => Array
            (
                [0] => 19.00
                [1] => 22.00
            )

        [part2] => Array
            (
                [0] => 
                [1] => 
            )

    )
 )

How will i get date as shown above with key 0. I can get others as

$string->day1->part1[0] How can i get date "12.06.2015" ? This seems to be complicated.

JSON string for reference

 {"day1":{"0":"12.06.2015","part1":["19.00","22.00"],"part2":["",""]},"day2":{"0":"13.06.2015","part1":["09.00","12.00"],"part2":["13.00","17.00"]}} 

used json_decode to decode it.

Upvotes: 0

Views: 35

Answers (1)

AbraCadaver
AbraCadaver

Reputation: 78994

You can use this:

echo $string->day1->{0};

Or my preference, decode as an array with the second argument set to true in json_decode() to use this:

echo $string['day1'][0];

Upvotes: 3

Related Questions