
|
If you were logged in you would be able to see more operations.
|
Google issue summary
|
|
|
| Resolution Date: |
26/Jun/06 08:11 AM
|
To make sure that the JSON is properly decoded, I started with a PHP array:
$fruits = array (
"fruits" => array("a" => "apple", "b" => "banana", "c" => "cantelope"),
"numbers" => array(1, 2, 3, 4, 5, 6),
"holes" => array("first", "second", "third")
);
to make sure that JSON could encode the array and then use the results of encode to pass to decode to see if I get the same results (see below). When using an associative array (Test Case 1), the array is converted to an object since JSON an object is an unordered set of name/value pairs. However, when I decode the resulting JSON text, the object is converted to an array but the rest of the arrays are dropped (Test Case 1).
When I make the associative array a numerically indexed array
$fruits = array (
"fruits" => array("apple", "banana", "cantelope"),
"numbers" => array(1, 2, 3, 4, 5, 6),
"holes" => array("first", "second", "third")
);
the Zend:JSON encoder and decoder work properly (Test Case 2).
Test Case 1
Array ( [fruits] => Array ( [a] => apple [b] => banana [c] => cantelope ) [numbers] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 ) [holes] => Array ( [0] => first [1] => second [2] => third ) )
{"fruits" : {"a" : "apple", "b" : "banana", "c" : "cantelope"}, "numbers" : [1, 2, 3, 4, 5, 6], "holes" : ["first", "second", "third"]}
Array ( [fruits] => Array ( [a] => apple [b] => banana [c] => cantelope ) )
Test Case 2
Array ( [fruits] => Array ( [0] => apple [1] => banana [2] => cantelope ) [numbers] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 ) [holes] => Array ( [0] => first [1] => second [2] => third ) )
{"fruits" : ["apple", "banana", "cantelope"], "numbers" : [1, 2, 3, 4, 5, 6], "holes" : ["first", "second", "third"]}
Array ( [fruits] => Array ( [0] => apple [1] => banana [2] => cantelope ) [numbers] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 ) [holes] => Array ( [0] => first [1] => second [2] => third ) )
|
|
Description
|
To make sure that the JSON is properly decoded, I started with a PHP array:
$fruits = array (
"fruits" => array("a" => "apple", "b" => "banana", "c" => "cantelope"),
"numbers" => array(1, 2, 3, 4, 5, 6),
"holes" => array("first", "second", "third")
);
to make sure that JSON could encode the array and then use the results of encode to pass to decode to see if I get the same results (see below). When using an associative array (Test Case 1), the array is converted to an object since JSON an object is an unordered set of name/value pairs. However, when I decode the resulting JSON text, the object is converted to an array but the rest of the arrays are dropped (Test Case 1).
When I make the associative array a numerically indexed array
$fruits = array (
"fruits" => array("apple", "banana", "cantelope"),
"numbers" => array(1, 2, 3, 4, 5, 6),
"holes" => array("first", "second", "third")
);
the Zend:JSON encoder and decoder work properly (Test Case 2).
Test Case 1
Array ( [fruits] => Array ( [a] => apple [b] => banana [c] => cantelope ) [numbers] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 ) [holes] => Array ( [0] => first [1] => second [2] => third ) )
{"fruits" : {"a" : "apple", "b" : "banana", "c" : "cantelope"}, "numbers" : [1, 2, 3, 4, 5, 6], "holes" : ["first", "second", "third"]}
Array ( [fruits] => Array ( [a] => apple [b] => banana [c] => cantelope ) )
Test Case 2
Array ( [fruits] => Array ( [0] => apple [1] => banana [2] => cantelope ) [numbers] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 ) [holes] => Array ( [0] => first [1] => second [2] => third ) )
{"fruits" : ["apple", "banana", "cantelope"], "numbers" : [1, 2, 3, 4, 5, 6], "holes" : ["first", "second", "third"]}
Array ( [fruits] => Array ( [0] => apple [1] => banana [2] => cantelope ) [numbers] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 ) [holes] => Array ( [0] => first [1] => second [2] => third ) ) |
Show » |
|
Test Case 1
Array ( [fruits] => Array ( [a] => apple [b] => banana [c] => cantelope ) [numbers] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 ) [holes] => Array ( [0] => first [1] => second [2] => third ) )
{"fruits":{"a":"apple","b":"banana","c":"cantelope"},"numbers":[1,2,3,4,5,6],"holes":["first","second","third"]}
stdClass Object ( [fruits] => stdClass Object ( [a] => apple [b] => banana [c] => cantelope ) [numbers] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 ) [holes] => Array ( [0] => first [1] => second [2] => third ) )
Test Case 2
{"fruits":["apple","banana","cantelope"],"numbers":[1,2,3,4,5,6],"holes":["first","second","third"]}Array ( [fruits] => Array ( [0] => apple [1] => banana [2] => cantelope ) [numbers] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 ) [holes] => Array ( [0] => first [1] => second [2] => third ) )
stdClass Object ( [fruits] => Array ( [0] => apple [1] => banana [2] => cantelope ) [numbers] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 ) [holes] => Array ( [0] => first [1] => second [2] => third ) )