Question

I'm using tmhOAuth library to parse twitter stream in php.

It returned me variable $data with this object

object sample for stackoverflow

{
   "created_at":"Wed Jan 02 13:37:54 +0000 2013",
   "id":286466350610776064,
   "id_str":"286466350610776064",
   ...
}

looks like simple object, but how pull some data from this object?

$data->created_at doesn't work, it broke my head, why??

Was it helpful?

Solution

Isn't it because probably you don't see that this is a string containing Json and you need to decode it first otherwise it's just a string variable and not an object?

See json_decodeDocs:

$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';

var_dump(json_decode($json));

object(stdClass)#1 (5) {
    ["a"] => int(1)
    ["b"] => int(2)
    ["c"] => int(3)
    ["d"] => int(4)
    ["e"] => int(5)
}

OTHER TIPS

This is JSON response. Try json_decode

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top