Annotation of embedaddon/php/ext/json/tests/pass003.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: JSON (http://www.crockford.com/JSON/JSON_checker/test/pass3.json)
! 3: --SKIPIF--
! 4: <?php
! 5: if (!extension_loaded('json')) die('skip: json extension not available');
! 6: ?>
! 7: --FILE--
! 8: <?php
! 9:
! 10: $test = '
! 11: {
! 12: "JSON Test Pattern pass3": {
! 13: "The outermost value": "must be an object or array.",
! 14: "In this test": "It is an object."
! 15: }
! 16: }
! 17: ';
! 18:
! 19: echo 'Testing: ' . $test . "\n";
! 20: echo "DECODE: AS OBJECT\n";
! 21: $obj = json_decode($test);
! 22: var_dump($obj);
! 23: echo "DECODE: AS ARRAY\n";
! 24: $arr = json_decode($test, true);
! 25: var_dump($arr);
! 26:
! 27: echo "ENCODE: FROM OBJECT\n";
! 28: $obj_enc = json_encode($obj);
! 29: echo $obj_enc . "\n";
! 30: echo "ENCODE: FROM ARRAY\n";
! 31: $arr_enc = json_encode($arr);
! 32: echo $arr_enc . "\n";
! 33:
! 34: echo "DECODE AGAIN: AS OBJECT\n";
! 35: $obj = json_decode($obj_enc);
! 36: var_dump($obj);
! 37: echo "DECODE AGAIN: AS ARRAY\n";
! 38: $arr = json_decode($arr_enc, true);
! 39: var_dump($arr);
! 40:
! 41: ?>
! 42: --EXPECT--
! 43: Testing:
! 44: {
! 45: "JSON Test Pattern pass3": {
! 46: "The outermost value": "must be an object or array.",
! 47: "In this test": "It is an object."
! 48: }
! 49: }
! 50:
! 51: DECODE: AS OBJECT
! 52: object(stdClass)#1 (1) {
! 53: ["JSON Test Pattern pass3"]=>
! 54: object(stdClass)#2 (2) {
! 55: ["The outermost value"]=>
! 56: string(27) "must be an object or array."
! 57: ["In this test"]=>
! 58: string(16) "It is an object."
! 59: }
! 60: }
! 61: DECODE: AS ARRAY
! 62: array(1) {
! 63: ["JSON Test Pattern pass3"]=>
! 64: array(2) {
! 65: ["The outermost value"]=>
! 66: string(27) "must be an object or array."
! 67: ["In this test"]=>
! 68: string(16) "It is an object."
! 69: }
! 70: }
! 71: ENCODE: FROM OBJECT
! 72: {"JSON Test Pattern pass3":{"The outermost value":"must be an object or array.","In this test":"It is an object."}}
! 73: ENCODE: FROM ARRAY
! 74: {"JSON Test Pattern pass3":{"The outermost value":"must be an object or array.","In this test":"It is an object."}}
! 75: DECODE AGAIN: AS OBJECT
! 76: object(stdClass)#3 (1) {
! 77: ["JSON Test Pattern pass3"]=>
! 78: object(stdClass)#4 (2) {
! 79: ["The outermost value"]=>
! 80: string(27) "must be an object or array."
! 81: ["In this test"]=>
! 82: string(16) "It is an object."
! 83: }
! 84: }
! 85: DECODE AGAIN: AS ARRAY
! 86: array(1) {
! 87: ["JSON Test Pattern pass3"]=>
! 88: array(2) {
! 89: ["The outermost value"]=>
! 90: string(27) "must be an object or array."
! 91: ["In this test"]=>
! 92: string(16) "It is an object."
! 93: }
! 94: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>