README 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. json 1.2.0
  2. ==========
  3. This extension implements the JavaScript Object Notation (JSON)
  4. data-interchange format as specified in [0].
  5. Two functions are implemented: encoding and decoding. The decoding
  6. is handled by a parser based on JSON_checker[1] by Douglas Crockford.
  7. Function overview
  8. -----------------
  9. string json_encode ( mixed value )
  10. json_encode returns a string containing the JSON representation of value.
  11. value can be any type except a resource.
  12. mixed json_decode ( string json, [bool assoc] )
  13. json_decode takes a JSON string and converts it into a PHP variable.
  14. When assoc is given, and evaluates to TRUE, json_decode() will return
  15. any objects as associative arrays.
  16. Example usage
  17. -------------
  18. $arr = array("a"=>1,"b"=>2,"c"=>3,"d"=>4,"e"=>5);
  19. echo json_encode($arr);
  20. ---> {"a":1,"b":2,"c":3,"d":4,"e":5}
  21. $json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
  22. var_dump(json_decode($json));
  23. ---> object(stdClass)#1 (5) {
  24. ["a"]=>
  25. int(1)
  26. ["b"]=>
  27. int(2)
  28. ["c"]=>
  29. int(3)
  30. ["d"]=>
  31. int(4)
  32. ["e"]=>
  33. int(5)
  34. }
  35. $json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
  36. var_dump(json_decode($json, true));
  37. ---> array(5) {
  38. ["a"]=>
  39. int(1)
  40. ["b"]=>
  41. int(2)
  42. ["c"]=>
  43. int(3)
  44. ["d"]=>
  45. int(4)
  46. ["e"]=>
  47. int(5)
  48. }
  49. Authors
  50. -------
  51. Omar Kilani <omar@php.net>
  52. ---
  53. [0] http://www.crockford.com/JSON/draft-jsonorg-json-00.txt
  54. [1] http://www.crockford.com/JSON/JSON_checker/