Parse JSON Data


/ Published in: PHP
Save to your folder(s)

With most of the popular web services like Twitter providing their data through APIs, it is always helpful to know how to parse API data which is sent in various formats including JSON, XML etc.


Copy this code and paste it in your HTML
  1. $json_string='{"id":1,"name":"foo","email":"[email protected]","interest":["wordpress","php"]} ';
  2. $obj=json_decode($json_string);
  3. echo $obj->name; //prints foo
  4. echo $obj->interest[1]; //prints php

Report this snippet


Comments


You need to login to view comments.