/** * Construct a JSONArray from a source JSON text. * * @param source * A string that begins with <code>[</code> <small>(left * bracket)</small> and ends with <code>]</code> <small>(right * bracket)</small>. * @throws JSONException * If there is a syntax error. */ public JSONArray(String source) throws JSONException { this(new JSONTokener(source)); }
/** * Construct a JSONArray from a source JSON text. * * @param source * A string that begins with <code>[</code> <small>(left * bracket)</small> and ends with <code>]</code> <small>(right * bracket)</small>. * @throws JSONException * If there is a syntax error. */ public JSONArray(String source) throws JSONException { this(new JSONTokener(source)); }
/** * Construct a JSONObject from a source JSON text string. This is the most * commonly used JSONObject constructor. * * @param source * A string beginning with <code>{</code> <small>(left * brace)</small> and ending with <code>}</code> <small>(right * brace)</small>. * @exception JSONException * If there is a syntax error in the source string or a * duplicated key. */ public JSONObject(String source) throws JSONException { this(new JSONTokener(source)); }
/** * Construct a JSONObject from a source JSON text string. This is the most * commonly used JSONObject constructor. * * @param source * A string beginning with <code>{</code> <small>(left * brace)</small> and ending with <code>}</code> <small>(right * brace)</small>. * @exception JSONException * If there is a syntax error in the source string or a * duplicated key. */ public JSONObject(String source) throws JSONException { this(new JSONTokener(source)); }
/** * Produce a JSONArray of JSONObjects from a comma delimited text string, * using the first row as a source of names. * @param string The comma delimited text. * @return A JSONArray of JSONObjects. * @throws JSONException */ public static JSONArray toJSONArray(String string) throws JSONException { return toJSONArray(new JSONTokener(string)); }
/** * Produce a JSONArray of JSONObjects from a comma delimited text string * using a supplied JSONArray as the source of element names. * @param names A JSONArray of strings. * @param string The comma delimited text. * @return A JSONArray of JSONObjects. * @throws JSONException */ public static JSONArray toJSONArray(JSONArray names, String string) throws JSONException { return toJSONArray(names, new JSONTokener(string)); }
/** * Produce a JSONArray of JSONObjects from a comma delimited text string * using a supplied JSONArray as the source of element names. * @param names A JSONArray of strings. * @param string The comma delimited text. * @return A JSONArray of JSONObjects. * @throws JSONException */ public static JSONArray toJSONArray(JSONArray names, String string) throws JSONException { return toJSONArray(names, new JSONTokener(string)); }
/** Transforming the JSON on the fly */ protected Object unmarshal() throws IOException, JSONException { json = new JSONTokener(new InputStreamReader(inputStream, "UTF-8")).nextValue(); inputStream.close(); return json; }
/** * Produce a JSONArray of JSONObjects from a comma delimited text string, * using the first row as a source of names. * @param string The comma delimited text. * @return A JSONArray of JSONObjects. * @throws JSONException */ public static JSONArray toJSONArray(String string) throws JSONException { return toJSONArray(new JSONTokener(string)); }
/** Transforming the JSON on the fly */ protected Object unmarshal() throws IOException, JSONException { json = new JSONTokener(new InputStreamReader(inputStream, "UTF-8")).nextValue(); inputStream.close(); return json; }
/** * Convert a cookie list into a JSONObject. A cookie list is a sequence * of name/value pairs. The names are separated from the values by '='. * The pairs are separated by ';'. The names and the values * will be unescaped, possibly converting '+' and '%' sequences. * * To add a cookie to a cooklist, * cookielistJSONObject.put(cookieJSONObject.getString("name"), * cookieJSONObject.getString("value")); * @param string A cookie list string * @return A JSONObject * @throws JSONException */ public static JSONObject toJSONObject(String string) throws JSONException { JSONObject o = new JSONObject(); JSONTokener x = new JSONTokener(string); while (x.more()) { String name = Cookie.unescape(x.nextTo('=')); x.next('='); o.put(name, Cookie.unescape(x.nextTo(';'))); x.next(); } return o; }
System.out.println(""); JSONTokener jt = new JSONTokener("{op:'test', to:'session', pre:1}{op:'test', to:'session', pre:2}"); j = new JSONObject(jt); System.out.println(j.toString());
System.out.println(""); JSONTokener jt = new JSONTokener("{op:'test', to:'session', pre:1}{op:'test', to:'session', pre:2}"); j = new JSONObject(jt); System.out.println(j.toString());
/** * Convert a cookie list into a JSONObject. A cookie list is a sequence * of name/value pairs. The names are separated from the values by '='. * The pairs are separated by ';'. The names and the values * will be unescaped, possibly converting '+' and '%' sequences. * * To add a cookie to a cooklist, * cookielistJSONObject.put(cookieJSONObject.getString("name"), * cookieJSONObject.getString("value")); * @param string A cookie list string * @return A JSONObject * @throws JSONException */ public static JSONObject toJSONObject(String string) throws JSONException { JSONObject o = new JSONObject(); JSONTokener x = new JSONTokener(string); while (x.more()) { String name = Cookie.unescape(x.nextTo('=')); x.next('='); o.put(name, Cookie.unescape(x.nextTo(';'))); x.next(); } return o; }
JSONObject o = new JSONObject(); Object v; JSONTokener x = new JSONTokener(string); o.put("name", x.nextTo('=')); x.next('=');
JSONObject o = new JSONObject(); Object v; JSONTokener x = new JSONTokener(string); o.put("name", x.nextTo('=')); x.next('=');