/** * Put a value in the JSONArray, where the value will be a * JSONObject which is produced from a Map. * @param value A Map value. * @return this. */ public JSONArray put(Map value) { put(new JSONObject(value)); return this; }
/** * Put a key/value pair in the JSONObject, where the value will be a * JSONObject which is produced from a Map. * @param key A key string. * @param value A Map value. * @return this. * @throws JSONException */ public JSONObject put(String key, Map value) throws JSONException { put(key, new JSONObject(value)); return this; }
/** * Put a value in the JSONArray, where the value will be a * JSONObject that is produced from a Map. * @param index The subscript. * @param value The Map value. * @return this. * @throws JSONException If the index is negative or if the the value is * an invalid number. */ public JSONArray put(int index, Map value) throws JSONException { put(index, new JSONObject(value)); return this; }
return new JSONObject((Map)object); return object.toString(); return new JSONObject(object); } catch(JSONException exception) { return null;
JSONObject nextTarget = target.optJSONObject(segment); if (nextTarget == null) { nextTarget = new JSONObject(); target.put(segment.toLowerCase(), nextTarget);
jObj = new JSONObject(txt); } else if (txt.startsWith("[")){ jObj = new JSONArray(txt); + e.getMessage()); try { jObj = new JSONObject("{}"); } catch (JSONException ex) { onMalformedJson("Error parsing empty row. This should never happen.");
/** * Serializes a Hive map<> using a JSONObject. * * @param obj the object to serialize * @param moi the object's inspector * @return */ private JSONObject serializeMap(Object obj, MapObjectInspector moi) { if (obj==null) { return null; } JSONObject jo = new JSONObject(); Map m = moi.getMap(obj); for(Object k : m.keySet()) { try { jo.put( serializeField(k, moi.getMapKeyObjectInspector()).toString(), serializeField(m.get(k), moi.getMapValueObjectInspector()) ); } catch (JSONException ex) { LOG.warn("Problem serializing map"); } } return jo; }
/** * Begin appending a new object. All keys and values until the balancing * <code>endObject</code> will be appended to this object. The * <code>endObject</code> method must be called to mark the object's end. * @return this * @throws JSONException If the nesting is too deep, or if the object is * started in the wrong place (for example as a key or after the end of the * outermost array or object). */ public JSONWriter object() throws JSONException { if (this.mode == 'i') { this.mode = 'o'; } if (this.mode == 'o' || this.mode == 'a') { this.append("{"); this.push(new JSONObject()); this.comma = false; return this; } throw new JSONException("Misplaced object."); }
case '{': back(); return new JSONObject(this); case '[': back();
/** * 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 and arrays of values. JSON does not * does not like to distinguish between elements and attributes. * 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. * @param string The source string. * @return A JSONObject containing the structured data from the XML string. * @throws JSONException */ public static JSONObject toJSONObject(String string) throws JSONException { JSONObject jo = new JSONObject(); XMLTokener x = new XMLTokener(string); while (x.more() && x.skipPast("<")) { parse(x, jo, null); } return jo; }
JSONObject result = new JSONObject();
return new JSONObject((Map)value).toString(indentFactor, indent);
/** * Produce a JSONObject by combining a JSONArray of names with the values * of this JSONArray. * @param names A JSONArray containing a list of key strings. These will be * paired with the values. * @return A JSONObject, or null if there are no names or if this JSONArray * has no values. * @throws JSONException If any of the names are null. */ public JSONObject toJSONObject(JSONArray names) throws JSONException { if (names == null || names.length() == 0 || length() == 0) { return null; } JSONObject jo = new JSONObject(); for (int i = 0; i < names.length(); i += 1) { jo.put(names.getString(i), this.opt(i)); } return jo; }
return new JSONObject((Map)value).toString();
JSONObject res = new JSONObject(result.toString()); assertEquals(res.getString("atext"), row.get(0));
/** * 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 jo = new JSONObject(); JSONTokener x = new JSONTokener(string); while (x.more()) { String name = Cookie.unescape(x.nextTo('=')); x.next('='); jo.put(name, Cookie.unescape(x.nextTo(';'))); x.next(); } return jo; }
JSONObject jo = new JSONObject(); Object value; JSONTokener x = new JSONTokener(string);
JSONObject jo = new JSONObject(); HTTPTokener x = new HTTPTokener(string); String token;
tagName = (String)token; token = null; jsonobject = new JSONObject(); for (;;) { if (token == null) {
newjo = new JSONObject(); if (arrayForm) { newja.put(tagName);