Create JSON with json_encode and json_decode using PHP

Laravel Mysql Mysqli php Programming

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.   PHP Convert multi-dimentional array into single array
  2.   PHP Redirect To Another page Example
  3.   Converting JSON Object into Javascript PHP array
  4.   PHP Add JSON object Data Example
  5.   Laravel 5.6 Sending Emails using SMTP Tutorial
  6.   Concept of Encapsulation in PHP OOP Example
  7.   jQuery Parsing PHP JSON Data
  8.   WooCommerce Get Product ID
  9.   How TO Check if checkbox is checked with jQuery?
  10.   Simple Jquery Ajax Pagination with Laravel 5.7 Example

Leave a Reply

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