Convert xml to json without conversion String/Integer?

6.6k views Asked by At

I would like to convert XML to JSON.

Currently, I make this with the lib org.json :

JSONObject jso = XML.toJSONObject(xmlStr);

However, if the XML contains number fields, I would like to have only String fields in the JSONObject.

For example:

The XML file is :

<ID>3</ID>
<NAME>ApplicationName</NAME>

The org.json permits me to have:

{
    "ID" : 3,
    "Name" : "ApplicationName"
}

The final result has to be :

{
    "ID" : "3",
    "Name" : "ApplicationName"
}
1

There are 1 answers

1
J.Canonne On BEST ANSWER

I resolve mt problem by using the latest version of org.json.

There is a methode to do this :

JSONObject jso = XML.toJSONObject(xmlStr, true);

The boolean is using to keep the string fields.