Create JSON with json_encode and json_decode using PHP

Create JSON with json_encode and json_decode using PHP

In this Post We Will Explain About is Create JSON with json_encode and json_decode using PHP With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Converting Object to JSON and JSON to Object in PHPExample

In this post we will show you Best way to implement Using PHP’s JSON encode and decode functions, hear for PHP and JSON – json_encode and json_decodewith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Also Read :  Automatically Post On Facebook Using PHP with Graph API

Below is simple as well as a small example of PHP function json_encode() & json_decode().

Step 1: Create Json using PHP

<?php
$json_edata = array("client_details" => array(array("cname" => "Dhameliya Mayur", "salary" => "180000")), "work_post" => array(array("company_name" => "live24u", "role" => "Seniour Manager", "person" => "91")));
$live_json_encode = json_encode($json_edata);
echo $live_json_encode."<br/>";
?>

Step 2 : Decode the JSON : using json_decode() functions

<?php
$json_edata = array("client_details" => array(array("cname" => "Dhameliya Mayur", "salary" => "180000")), "work_post" => array(array("company_name" => "live24u", "role" => "Seniour Manager", "person" => "91")));
$live_json_encode = json_encode($json_edata);
echo $live_json_encode."<br/>";
 
$obj = json_decode($live_json_encode);
 
foreach($obj->client_details as $udetails){
    echo $udetails->cname;
    echo "<br/>";
    echo $udetails->salary;
    echo "<br/>";
}
foreach($obj->work_post as $wdetails){
    echo $wdetails->company_name;
    echo "<br/>";
    echo $wdetails->salary;
    echo "<br/>";
}
?>

Example

Also Read :  Multiple Image Upload using PHP into MYSQL database

I hope you have Got What is php – Convert Object of class stdClass to JSON Object And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.

Leave a Reply

Your email address will not be published. Required fields are marked *