pass003.phpt 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. --TEST--
  2. JSON (http://www.crockford.com/JSON/JSON_checker/test/pass3.json)
  3. --FILE--
  4. <?php
  5. $test = '
  6. {
  7. "JSON Test Pattern pass3": {
  8. "The outermost value": "must be an object or array.",
  9. "In this test": "It is an object."
  10. }
  11. }
  12. ';
  13. echo 'Testing:' . $test . "\n";
  14. echo "DECODE: AS OBJECT\n";
  15. $obj = json_decode($test);
  16. var_dump($obj);
  17. echo "DECODE: AS ARRAY\n";
  18. $arr = json_decode($test, true);
  19. var_dump($arr);
  20. echo "ENCODE: FROM OBJECT\n";
  21. $obj_enc = json_encode($obj);
  22. echo $obj_enc . "\n";
  23. echo "ENCODE: FROM ARRAY\n";
  24. $arr_enc = json_encode($arr);
  25. echo $arr_enc . "\n";
  26. echo "DECODE AGAIN: AS OBJECT\n";
  27. $obj = json_decode($obj_enc);
  28. var_dump($obj);
  29. echo "DECODE AGAIN: AS ARRAY\n";
  30. $arr = json_decode($arr_enc, true);
  31. var_dump($arr);
  32. ?>
  33. --EXPECTF--
  34. Testing:
  35. {
  36. "JSON Test Pattern pass3": {
  37. "The outermost value": "must be an object or array.",
  38. "In this test": "It is an object."
  39. }
  40. }
  41. DECODE: AS OBJECT
  42. object(stdClass)#%d (1) {
  43. ["JSON Test Pattern pass3"]=>
  44. object(stdClass)#%d (2) {
  45. ["The outermost value"]=>
  46. string(27) "must be an object or array."
  47. ["In this test"]=>
  48. string(16) "It is an object."
  49. }
  50. }
  51. DECODE: AS ARRAY
  52. array(1) {
  53. ["JSON Test Pattern pass3"]=>
  54. array(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. ENCODE: FROM OBJECT
  62. {"JSON Test Pattern pass3":{"The outermost value":"must be an object or array.","In this test":"It is an object."}}
  63. ENCODE: FROM ARRAY
  64. {"JSON Test Pattern pass3":{"The outermost value":"must be an object or array.","In this test":"It is an object."}}
  65. DECODE AGAIN: AS OBJECT
  66. object(stdClass)#%d (1) {
  67. ["JSON Test Pattern pass3"]=>
  68. object(stdClass)#%d (2) {
  69. ["The outermost value"]=>
  70. string(27) "must be an object or array."
  71. ["In this test"]=>
  72. string(16) "It is an object."
  73. }
  74. }
  75. DECODE AGAIN: AS ARRAY
  76. array(1) {
  77. ["JSON Test Pattern pass3"]=>
  78. array(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. }