1//Json Encode
2
3$person = array(
4 "name" => "KINGASV",
5 "title" => "CTO"
6);
7$personJSON=json_encode($person);//returns JSON string
8
9//Json Decode
10
11$personJSON = '{"name":"KINGASV","title":"CTO"}';
12
13$person = json_decode($personJSON);
14
15echo $person->name; // KINGASV
16
1<?php
2 // JSON string
3 $someJSON = '[{"name":"Jonathan Suh","gender":"male"},{"name":"William Philbin","gender":"male"},{"name":"Allison McKinnery","gender":"female"}]';
4
5 // Convert JSON string to Object
6 $someObject = json_decode($someJSON);
7 echo $someObject[0]->name; // Access Object data
8?>
9
1<?php
2
3$data = '{
4 "name": "Aragorn",
5 "race": "Human"
6}';
7
8$character = json_decode($data);
9echo $character->name;