How To Read A Value From Json Using Php?

JSON (JavaScript Object Notation) is a convenient, readable too tardily to utilization information telephone substitution format that is both lightweight too human-readable(like XML, simply without the bunch of markup).

If y'all accept a json array too desire to read too impress its value, y'all accept to utilization php business office
json_decode(string $json, [optional{true, false}]).

If y'all transcend a valid JSON string into the json decode function, y'all volition transcend an object of type stdClass back. Here's a brusk example:
<?php $string = '{"first_name": "Anup", "last_name": "Shakya"}'; $result = json_decode($string);  // Result: stdClass Object ( [first_name] => Anup: [last_name] => Shakya  ) print_r($result);  // Prints "Anup" echo $result->first_name;  // Prints "Shakya" echo $result->last_name; ?> 

If y'all desire to transcend an associative array dorsum instead, gear upward the instant parameter to true:
<?php $string = '{"first_name": "Anup", "last_name": "Shakya"}'; $result = json_decode($string, true);  // Result: Array ( [first_name] => Anup: [last_name] => Shakya  ) print_r($result);  // Prints "Anup" echo $result['first_name'];  // Prints "Shakya" echo $result['last_name']; ?> 

If y'all desire to know to a greater extent than near JSON, hither is an official website of JSON.


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?