I'm using the library net.sf.json to convert an XML to a JSON. This is the code I wrote:
FileInputStream fis = new FileInputStream("C:\\Desktop\\TestXML.xml");
XMLSerializer xmlSerializer = new XMLSerializer();
JSON json = xmlSerializer.readFromStream(fis);
JSONArray jsonArray = new JSONArray();
jsonArray.add(json);
JSONObject root = new JSONObject();
root.element("WSJson", jsonArray);
I noticed that if the XML contains empty tags, they are transformed in empty arrays.
Example: given this xml
<WSJson>
<Tipo_Operazione>I</Tipo_Operazione>
<Codice_Prestazione>SW1</Codice_Prestazione>
<Codice_Intervento></Codice_Intervento>
<Nome/>
</WSJson>
the output is
{
"WSJson": [{
"Tipo_Operazione": "I",
"Codice_Prestazione": "SW1",
"Codice_Intervento": [],
"Nome": []
}]
}
Instead, I would like to have
{
"WSJson": [{
"Tipo_Operazione": "I",
"Codice_Prestazione": "SW1",
"Codice_Intervento": "",
"Nome": ""
}]
}
Can anyone help?