History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: ZF-59
Type: Bug Bug
Status: Closed Closed
Resolution: Duplicate
Priority: Major Major
Assignee: Matthew Weier O'Phinney
Reporter: Gary Krajci
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Google issue summary
Zend Framework

Possible Problem with Zend_Json::decode

Created: 20/Jun/06 06:54 AM   Updated: 05/Jul/07 02:44 PM
Component/s: Zend_Json
Affects Version/s: 0.1.3
Fix Version/s: 0.1.4

Time Tracking:
Not Specified

Resolution Date: 26/Jun/06 08:11 AM


 Description  « Hide
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 ) )



 All   Comments   Work Log   Change History   FishEye   Crucible      Sort Order: Ascending order - Click to sort in descending order
Gary Krajci - 20/Jun/06 12:01 PM
FYI: I was checking out AJASON (http://ajason.fantastic-bits.de/index.php?link_id=40) and the JSON parser that is inlcuded in the distribution correctly handles the associative array:

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
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"]}

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 ) )


Jean-Baptiste Feldis - 21/Jun/06 02:23 AM
Hi everyone,

i posted an ticket concerning this issue a few weeks ago and it appears to have been fixed:
05/31/06 12:24:18: Modified by gavin

  • owner changed from zend to matthew.
    06/13/06 04:59:05: Modified by matthew
  • status changed from new to closed.
  • resolution set to fixed.

Fixed in [620]; tested in [621].

Here is the link to the OLD ticket: http://framework.zend.com/developer/ticket/107


Gary Krajci - 21/Jun/06 05:32 AM
I appreciate the update; however, I just downloaded and tested the ZIP and the TAR.GZ Zend Framework, Preview 0.1.3, Released on April 18, 2006 and tested it again, and it failed again.

If it was fixed, the fix may not have been included in Preview 0.1.3 (CM mistake).


Matthew Weier O'Phinney - 26/Jun/06 08:11 AM
The issue was corrected post 0.1.3, and the fix will be present in 0.1.4; it is already in curren SVN.