/** * Convert a JSONObject into a well-formed, element-normal XML string.<p> * * @param o a JSONObject * @return a string * @throws JSONException if something goes wrong */ public static String toString(Object o) throws JSONException { return toString(o, null); }
b.append('\n'); b.append(escape(ja.get(i).toString())); b.append(escape(v.toString())); len = ja.length(); for (i = 0; i < len; i += 1) { b.append(toString(ja.get(i), k)); b.append(toString(v, k)); len = ja.length(); for (i = 0; i < len; ++i) { b.append(toString(ja.opt(i), (tagName == null) ? "array" : tagName)); s = (o == null) ? "null" : escape(o.toString()); return (tagName == null) ? "\"" + s + "\""
/** * Convert a well-formed (but not necessarily valid) XML string into a * JSONObject.<p> * * 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 and arrays of values. JSON does not * does not like to distinguish between elements and attributes.<p> * * Sequences of similar elements are represented as JSONArrays. Content * text may be placed in a "content" member. Comments, prologs, DTDs, and * <code><[ [ ]]></code> are ignored.<p> * * @param string the source string * @return a JSONObject containing the structured data from the XML string * @throws JSONException if something goes wrong */ public static JSONObject toJSONObject(String string) throws JSONException { JSONObject o = new JSONObject(); XMLTokener x = new XMLTokener(string); while (x.more() && x.skipPast("<")) { parse(x, o, null); } return o; }
b.append('\n'); b.append(escape(ja.get(i).toString())); b.append(escape(v.toString())); len = ja.length(); for (i = 0; i < len; i += 1) { b.append(toString(ja.get(i), k)); b.append(toString(v, k)); len = ja.length(); for (i = 0; i < len; ++i) { b.append(toString(ja.opt(i), (tagName == null) ? "array" : tagName)); s = (o == null) ? "null" : escape(o.toString()); return (tagName == null) ? "\"" + s + "\"" : (s.length() == 0) ? "<" + tagName + "/>" : "<" + tagName
/** * Convert a well-formed (but not necessarily valid) XML string into a * JSONObject.<p> * * 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 and arrays of values. JSON does not * does not like to distinguish between elements and attributes.<p> * * Sequences of similar elements are represented as JSONArrays. Content * text may be placed in a "content" member. Comments, prologs, DTDs, and * <code><[ [ ]]></code> are ignored.<p> * * @param string the source string * @return a JSONObject containing the structured data from the XML string * @throws JSONException if something goes wrong */ public static JSONObject toJSONObject(String string) throws JSONException { JSONObject o = new JSONObject(); XMLTokener x = new XMLTokener(string); while (x.more() && x.skipPast("<")) { parse(x, o, null); } return o; }
if (parse(x, o, n)) { if (o.length() == 0) { context.accumulate(n, "");
/** * Convert a JSONObject into a well-formed, element-normal XML string.<p> * * @param o a JSONObject * @return a string * @throws JSONException if something goes wrong */ public static String toString(Object o) throws JSONException { return toString(o, null); }
if (parse(x, o, n)) { if (o.length() == 0) { context.accumulate(n, "");