X Tutup
Skip to content

Issue with xml.java package #394

@raviteja713

Description

@raviteja713

Trying to convert JSON data into XML string using the below logic of code snippet. But, output xml has a JSONObject being displayed after "content" attribute as show below. Any suggestions.?

# input.json:

{
  "id": "0001",
  "type": "donut",
  "name": "Cake",
  "payload": {
	"uname":"David"
    "content": {
      "batter": [
        {
          "id": "1001",
          "type": "Regular",
          "mode": [
            "rel",
            "don"
          ]
        }
      ]
    }
  }
}

jsontoxml.java:

org.json.JSONObject jsonObject = new org.json.JSONObject(jsonData);
string xml="<?xml version=\"1.0\" encoding=\"ISO-8859-15\"?>\n<"+root+">" + org.json.XML.toString(jsonObject) + "</"+root+">

output.xml:

<?xml version="1.0" encoding="ISO-8859-15"?>
<root>
    <id>0001</id>
    <type>donut</type>
    <name>Cake</name>  
	<payload>
        <uname>David</uname>
        {"batter": [{"id": "1001","type": "Regular","mode": ["rel","don"]}]}
    </payload>
</root>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup