Convert a well-formed (but not necessarily valid) XML string into a JSONObject. Some information may be lost in this transformation because JSON is a data format and XML is a document format. XML uses elements, attributes, and content text, while JSON uses unordered collections of name/value pairs a
(String string)
| 359 | * @return A JSONObject containing the structured data from the XML string. |
| 360 | */ |
| 361 | public static JSONObject toJSONObject(String string) throws JSONException { |
| 362 | JSONObject jo = new JSONObject(); |
| 363 | XMLTokener x = new XMLTokener(string); |
| 364 | while (x.more() && x.skipPast("<")) { |
| 365 | parse(x, jo, null); |
| 366 | } |
| 367 | return jo; |
| 368 | } |
| 369 | |
| 370 | /** |
| 371 | * Convert a JSONObject into a well-formed, element-normal XML string. |