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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: chenming522 at gmail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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: Sun Nov 03 19:01:28 2024 UTC