Thursday, August 11, 2011

PHP JSON

Hi friends,
If we want to get data from an url which .json format, here is the code..
$url = "yoururl.json";
$json = @file_get_contents($url);
$statuses = json_decode($json);

Now the all details in that url will be in variable $statuses .

If suppose we to get data from HTML tag which is named text

$status_text = $statuses->text;
If we are having number of text tag and we want 1st tag we have to mention as array
$status_text = $statuses[0]->text;

If we want to get value from element which is inside the element user then

$name = $statuses[0]->user->text;

No comments:

Post a Comment