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!.

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

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.


Related FAQ

Here are some more FAQ related to this Article:

  1.   Create dynamic calendar using jQuery, Ajax and PHP
  2.   jQuery Parsing PHP JSON Data
  3.   Best Most Popular JavaScript Frameworks comparison
  4.   Create Order and Invoice using Magento
  5.   PHP Add JSON object Data Example
  6.   PayPal Payment Gateway with PHP MySQL Database
  7.   Simple Materialize CSS Autocomplete Ajax using PHP
  8.   Converting JSON Object into Javascript PHP array
  9.   How to String Replace in PHP Functions?
  10.   How to Get Current Date and Time in PHP?

Leave a Reply

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