Issues

ZF-59: Possible Problem with Zend_Json::decode

Issue Type: Bug Created: 2006-06-20T06:54:51.000+0000 Last Updated: 2007-07-05T14:44:28.000+0000 Status: Closed Fix version(s): - 0.1.4 (29/Jun/06)

Reporter: Gary Krajci (zekethegeek) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Json

Related issues: Attachments:

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

Comments

Posted by Gary Krajci (zekethegeek) on 2006-06-20T12:01:26.000+0000

FYI: I was checking out AJASON (http://ajason.fantastic-bits.de/index.php/…) 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 ) )

Posted by Jean-Baptiste Feldis (atruskor) on 2006-06-21T02:23:38.000+0000

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]

Posted by Gary Krajci (zekethegeek) on 2006-06-21T05:32:26.000+0000

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

Posted by Matthew Weier O'Phinney (matthew) on 2006-06-26T08:11:16.000+0000

The issue was corrected post 0.1.3, and the fix will be present in 0.1.4; it is already in curren SVN.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts