From: chenming522 at gmail dot com
Operating system: windows xp
PHP version: 5.2.6
PHP Bug Type: Unknown/Other Function
Bug description: json_encode() bug report
Description:
------------
Hi:
I am a new gur for PHP program, Recently when I write a program that
use php function json_encode() to translate a simpleXML object into json
code, I found the attributes of the XML leafage node was lose.
Wait to solve :).
Thank you.
Reproduce code:
---------------
<?
$xml_str = "<root><node attr='node attribute'>node value</node></root>";
$xml_obj = simplexml_load_string($xml_str);
$json = json_encode($xml_obj);
echo $json; // so where is node's attribute
echo "\n=======================================\n";
$xml_str = "<root><node attr='node attribute'></node></root>";
$xml_obj = simplexml_load_string($xml_str);
$json = json_encode($xml_obj);
echo $json; // found it, but why?
?>
Expected result:
----------------
{"node":"node value"}
=======================================
{"node":{"@attributes":{"attr":"node attribute"}}}
Actual result:
--------------
inlude node's value and attributes
--
Edit bug report at http://bugs.php.net/?id=45878&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=45878&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=45878&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=45878&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=45878&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=45878&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=45878&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=45878&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=45878&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=45878&r=support
Expected behavior: http://bugs.php.net/fix.php?id=45878&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=45878&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=45878&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=45878&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=45878&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=45878&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=45878&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=45878&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=45878&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=45878&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=45878&r=mysqlcfg