How To Decode Json Data


[{

"name":"awnish",

"class":"12th",

"passed":true,

"marks":60


},

{

"name":"ravi",

"class":"11th",

"passed":false,

"marks":-10


},

{

"name":"mansa",

"class":"L.k.g",

"passed":"Not this Birth",

"marks":"-infinity"


},

{

"name":"Dubey",

"class":"Class Key Peechey",

"passed":"Bhool Jao",

"marks":"Tumharey Bas Ka Nahi"


}]



student_decode.php


 

<?php


$json_str=file_get_contents("student.json");//Json_string

$json_arr=json_decode($json_str);


//Classical Way


// $student_1 = $json_arr[0];

// $student_2 = $json_arr[1];

// $student_3 = $json_arr[2];

// $student_4 = $json_arr[3];


// echo "student Information 1:<hr/>";

// echo "Student Name : {$student_1->name} <br/>";

// echo "Student class : {$student_1->class} <br/>";

// echo "Student passed : {$student_1->passed } <br/>";

// echo "Student Marks : {$student_1->marks } <br/>";



// echo "student Information 2:<hr/>";

// echo "Student Name : {$student_2->name} <br/>";

// echo "Student class : {$student_2->class} <br/>";

// echo "Student passed : {$student_2->passed } <br/>";

// echo "Student Marks : {$student_2->marks } <br/>";


// echo "student Information 3:<hr/>";

// echo "Student Name : {$student_3->name} <br/>";

// echo "Student class : {$student_3->class} <br/>";

// echo "Student passed : {$student_3->passed } <br/>";

// echo "Student Marks : {$student_3->marks } <br/>";


// echo "student Information 4:<hr/>";

// echo "Student Name : {$student_4->name} <br/>";

// echo "Student class : {$student_4->class} <br/>";

// echo "Student passed : {$student_4->passed } <br/>";

// echo "Student Marks : {$student_4->marks } <br/>";


//Developers Approach


// How to validate Json_string http://jsonviewer.stack.hu/ Paste the Code and 

// Try to Parse if any error it will Tell.

// In Json Viewer ... Iterable

foreach($json_arr as $student):

echo "<hr/>";

echo "<b>Student data :</b>";

echo "<hr/>";

echo "Student Name : {$student->name} <br/>";

echo "Student class : {$student->class} <br/>";

echo "Student passed : {$student->passed } <br/>";

echo "Student Marks : {$student->marks } <br/>";

endforeach;