Return to README CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / json |
1.1 ! misho 1: json 1.2.0 ! 2: ========== ! 3: ! 4: This extension implements the JavaScript Object Notation (JSON) ! 5: data-interchange format as specified in [0]. ! 6: ! 7: Two functions are implemented: encoding and decoding. The decoding ! 8: is handled by a parser based on JSON_checker[1] by Douglas Crockford. ! 9: ! 10: ! 11: Function overview ! 12: ----------------- ! 13: ! 14: string json_encode ( mixed value ) ! 15: ! 16: json_encode returns a string containing the JSON representation of value. ! 17: value can be any type except a resource. ! 18: ! 19: mixed json_decode ( string json, [bool assoc] ) ! 20: ! 21: json_decode takes a JSON string and converts it into a PHP variable. ! 22: When assoc is given, and evaluates to TRUE, json_decode() will return ! 23: any objects as associative arrays. ! 24: ! 25: ! 26: Example usage ! 27: ------------- ! 28: ! 29: $arr = array("a"=>1,"b"=>2,"c"=>3,"d"=>4,"e"=>5); ! 30: echo json_encode($arr); ! 31: ! 32: ---> {"a":1,"b":2,"c":3,"d":4,"e":5} ! 33: ! 34: $json = '{"a":1,"b":2,"c":3,"d":4,"e":5}'; ! 35: var_dump(json_decode($json)); ! 36: ! 37: ---> object(stdClass)#1 (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: ! 50: $json = '{"a":1,"b":2,"c":3,"d":4,"e":5}'; ! 51: var_dump(json_decode($json, true)); ! 52: ! 53: ---> array(5) { ! 54: ["a"]=> ! 55: int(1) ! 56: ["b"]=> ! 57: int(2) ! 58: ["c"]=> ! 59: int(3) ! 60: ["d"]=> ! 61: int(4) ! 62: ["e"]=> ! 63: int(5) ! 64: } ! 65: ! 66: ! 67: Authors ! 68: ------- ! 69: ! 70: Omar Kilani <omar@php.net> ! 71: ! 72: ! 73: --- ! 74: ! 75: [0] http://www.crockford.com/JSON/draft-jsonorg-json-00.txt ! 76: [1] http://www.crockford.com/JSON/JSON_checker/