How To Read Json Information Reply Using Php?

This tutorial volition instruct you lot how to decode JSON objects using PHP. Reading a JSON is only every mo slow in addition to it only has to output a json string in addition to salve it to variable(for event $json_data), And immediately boot the bucket $json_data to json_decode business office in addition to read/parse.
Example JSON Response
 $json_data = '{       "stat": "ok",       "profile": {         "providerName": "testing",         "identifier": "http://testing.com/58263223",         "displayName": "testing 1",         "preferredUsername": "testing 2",         "name": {           "formatted": "testing"         },         "url": "http://testing.com/testing/",         "photo": "https://securecdn.testing.com/uploads/users/5826/3223/avatar32.jpg?1373393837",         "providerSpecifier": "testing"       }     }'; 
PHP json_decode() business office is used for decoding JSON inward PHP. This business office returns the value decoded from json to appropriate PHP type. The next examples shows how PHP tin sack hold upward used to decode JSON objects:
Alternative i (returns object format)
 $data = json_decode($json_data); echo $data->profile->displayName; // outputs testing i echo $data->profile->preferredUsername;// outputs testing ii 
Alternative ii (returns array format)
 $data = json_decode($json_data, true); $preferredUsername = $data['profile']['preferredUsername']; $displayName = $data['profile']['displayName']; 
Ref: http://stackoverflow.com/a/17865683
Sumber http://developer-paradize.blogspot.com

Comments

Popular posts from this blog

What Are The Main Components of a Computer System

Top Qualities To Look For In An IT Support Team

How To Integrate Google Adwords Api Into Codeigniter?