JSON object as php string

json, object, php, string

Solution

First of all, look up php's json_decode function. It will transform your JSON string to a data structure, and then you should be able to look up your hashtags like:

$data = json_decode($jsonstring, true);
$hashtags = $data['results'][0]['entities']['hashtags']; // this will be an array

I haven't tested it, but I think that is correct. In case it's not exactly right, you can read about json_decode() here: http://php.net/manual/en/function.json-decode.php

Problem

Possible Duplicate: Convert a JSON into a UTF-8 string I am working on caching some twitter feeds for long term use. The result of my search yields the following type of data structure: ``` "results": [ { "created_at": "Sun, 08 Apr 2012 18:31:04 +0000", "entities": { "hashtags": [ { "text": "cheeringfor", "indices": [ 54, 66 ] } ], "urls": [ ], "user_mentions": [ { "screen_name": "BenSpies11", "name": "Ben Spies", "id": 32124771, "id_str": "32124771", "indices": [ 0, 11 ] } ] },... ``` I am trying to include the hashtags section of this output in my database table but I am trying to save it as plain string. I have tried casting it as a string i:e `(string)$result->hashtags` but I get the cannot be converted to string error. I also tried the serialize() function which worked but got php errors when I tried to un-serialize and get my object back.

Original source

Related problems