tags:

views:

55

answers:

2

New to json data and struggling i guess the answer is real easy but been bugging me for the last hour..

Sample data

    {
   "data": 
      {
         "userid": "17",
         "dates": {
            "timestame": "1275528578",
                  },
         "username": "harino54",

      }

}

Ok I can pull userid or username easy enough with

echo "$t->userid" or echo "$t->username "

but how do I pull data from the brackets within ? in this case timestame?

cant seem to figure it out..

any ideas?

+2  A: 

It sounds like you are looking for something like this: echo "{$t->dates->timestame}";.

To access data from an object within quotes, you need to surround it with braces.

alternately, you could just say: echo $t->date->timestame; without the quotes.

Are you doing someting like this?

$t = json_decode($jsonString);
echo $t->data->dates->timestame;

or

$t = json_decode($jsonString);
echo "{$t->data->dates->timestame}";
zipcodeman
Can you post some more of your code then?
zipcodeman
without quotes worked thanks bud
Webby
+1  A: 
$t -> dates -> timestame
Ignacio Vazquez-Abrams
tried that and it returnsObject id #3->timestamp ??
Webby
Is that because of the spelling discrepancy (timestamp vs timestame)?
JustinStolle
@JustinStolle: No. It's because the asker has it in a string. Outside of a string it works perfectly.
Ignacio Vazquez-Abrams