php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45878 json_encode() bug report
Submitted: 2008-08-21 06:07 UTC Modified: 2008-08-21 20:49 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:0 of 2 (0.0%)
From: chenming522 at gmail dot com Assigned:
Status: Not a bug Package: JSON related
PHP Version: 5.2.6 OS: windows xp
Private report: No CVE-ID: None
 [2008-08-21 06:07 UTC] chenming522 at gmail dot com
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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-21 20:49 UTC] jani@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 15:01:28 2024 UTC