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
1function IsJsonString(str) {
2 try {
3 JSON.parse(str);
4 } catch (e) {
5 return false;
6 }
7 return true;
8}
1$data = json_decode(file_get_contents('php://input'), true);
2print_r($data);
3echo $data;
4
1<?php
2$jsonurl = "http://api.wipmania.com/json";
3$json = file_get_contents($jsonurl);
4var_dump(json_decode($json));
5?>
1function getJsonData(){
2 $var = get_object_vars($this);
3 foreach ($var as &$value) {
4 if (is_object($value) && method_exists($value,'getJsonData')) {
5 $value = $value->getJsonData();
6 }
7 }
8 return $var;
9}
10