java - XML to JSON - unexpected behaviour while converting lists? -
this json value:
{ "hello": [ { "names": { "name": "abc" } }, { "names": { "name": "def" } } ] }
i tried using xml.tostring(new jsonobject())
, , get:
<hello> <names> <name>abc</name> </names> </hello> <hello> <names> <name>def</name> </names> </hello>
whereas, xml expected this:
<hello> <names> <name>abc</name> </names> <names> <name>def</name> </names> </hello>
this unexpected behaviour results in invalid xml error, since there no root element now. missing here?
the issue in json code. []
means array, , definition array set of elements. resulting xml code contains set of hello
elements. try change []
{}
:
{ "hello": { "names": [ { "name": "abc" }, { "name": "def" } ] } }
just tried , got exact output you're looking for:
<hello> <names> <name>abc</name> </names> <names> <name>def</name> </names> </hello>
Comments
Post a Comment