toJSONObject

open fun toJSONObject(string: String): JSONObject

Convert a well-formed (but not necessarily valid) XML string into a JSONObject using the JsonML transform. Each XML tag is represented as a JSONObject with a "tagName" property. If the tag has attributes, then the attributes will be in the JSONObject as properties. If the tag contains children, the object will have a "childNodes" property which will be an array of strings and JsonML JSONObjects. Comments, prologs, DTDs, and

<[ [ ]]>
are ignored.

Return

A JSONObject containing the structured data from the XML string.

Parameters

string

The XML source text.

Throws

Thrown on error converting to a JSONObject


open fun toJSONObject(string: String, keepStrings: Boolean): JSONObject

Convert a well-formed (but not necessarily valid) XML string into a JSONObject using the JsonML transform. Each XML tag is represented as a JSONObject with a "tagName" property. If the tag has attributes, then the attributes will be in the JSONObject as properties. If the tag contains children, the object will have a "childNodes" property which will be an array of strings and JsonML JSONObjects. Comments, prologs, DTDs, and

<[ [ ]]>
are ignored.

Return

A JSONObject containing the structured data from the XML string.

Parameters

string

The XML source text.

keepStrings

If true, then values will not be coerced into boolean or numeric values and will instead be left as strings

Throws

Thrown on error converting to a JSONObject


Convert a well-formed (but not necessarily valid) XML string into a JSONObject using the JsonML transform. Each XML tag is represented as a JSONObject with a "tagName" property. If the tag has attributes, then the attributes will be in the JSONObject as properties. If the tag contains children, the object will have a "childNodes" property which will be an array of strings and JsonML JSONObjects. Comments, prologs, DTDs, and

<[ [ ]]>
are ignored.

Return

A JSONObject containing the structured data from the XML string.

Parameters

x

An XMLTokener of the XML source text.

Throws

Thrown on error converting to a JSONObject


open fun toJSONObject(x: XMLTokener, keepStrings: Boolean): JSONObject

Convert a well-formed (but not necessarily valid) XML string into a JSONObject using the JsonML transform. Each XML tag is represented as a JSONObject with a "tagName" property. If the tag has attributes, then the attributes will be in the JSONObject as properties. If the tag contains children, the object will have a "childNodes" property which will be an array of strings and JsonML JSONObjects. Comments, prologs, DTDs, and

<[ [ ]]>
are ignored.

Return

A JSONObject containing the structured data from the XML string.

Parameters

x

An XMLTokener of the XML source text.

keepStrings

If true, then values will not be coerced into boolean or numeric values and will instead be left as strings

Throws

Thrown on error converting to a JSONObject