I need to convert XML into JSON and I have the following code which works fine. The problem, however, arises when an XML element should actually be converted into an array. My question is in two parts:
1) What is the proper way to represent an array in xml?
Here is the xml I'm currently using. The contents of elements should actually be an array. So elements[0] should be the element within.
<project id="200">
<name>test</name>
<elements>
<element>
<id>body</id>
<width>200</width>
<height>400</height>
<children/>
</element>
</elements>
</project>
2) How can I convert the xml into JSON containing JSON arrays as well as objects?
private String xmlToJson(String xml) throws IOException {
JSONObject jsonObject = XML.toJSONObject(xml);
return jsonObject.toString(4);
} // End of XML to JSON
Many thanks