1$personJSON = '{"name":"Johny Carson","title":"CTO"}';
2
3$person = json_decode($personJSON);
4
5echo $person->name; // Johny Carson
1json_encode used when PHP retrieve data and convert Array() to [] !!!!
2$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
3echo json_encode($arr);
4//output
5{"a":1,"b":2,"c":3,"d":4,"e":5}
6access from js file data.a, data.b,data.c...
7----------------------------------------------
8 $json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
9json_decode($json, true); //true turns object to associative array;
10
11//output
12array(5) {
13 ["a"] => int(1)
14 ["b"] => int(2)
15 ["c"] => int(3)
16 ["d"] => int(4)
17 ["e"] => int(5)
18}
19
20
1<?php
2
3$json = '{"firstName":"Peter","lastName:":"Silva","age":23}';
4
5$personInfo = json_decode(json);
6
7echo $personInfo->age;
8
9?>
1//"[{\"name\": \"bill\", \"score\": 0.7948127388954163}, {\"name\": \"john\", \"score\": 0.782698392868042}]";
2//for json in above format try this
3$r=json_decode(stripcslashes(trim($response,'"')));