/** * Return a copy of the JSON content * @return JSONObject json */ public synchronized JSONObject toJSONObject(){ JSONObject res = new JSONObject(); res.putAll(this); return res; }
Map<String, Object> data = new HashMap<String, Object>(); data.put( "name", "Mars" ); data.put( "age", 32 ); data.put( "city", "NY" ); JSONObject json = new JSONObject(); json.putAll( data ); System.out.printf( "JSON: %s", json.toString(2) );
/** * create an campaign with a dumped map * @param campaignMap */ public Campaign(JSONObject campaignMap) { this(); this.map.putAll(campaignMap); this.start_time = ((Date) this.map.get("start_date")).getTime(); this.end_time = ((Date) this.map.get("end_date")).getTime(); this.id = DateParser.minuteDateFormat.format((Date) this.map.get("start_date")).replace(' ', '_') + "-" + DateParser.minuteDateFormat.format((Date) this.map.get("end_date")).replace(' ', '_') + "-" + Math.abs(((String) this.map.get("query")).hashCode()) + "-" + Math.abs(((String) this.map.get("name")).hashCode()); }
@Override public synchronized void putAll(JSONObject other){ super.putAll(other); commit(); }
/** * Merging of data is required during an mind-meld. * To meld two thoughts, we combine their data arrays into one. * The resulting table has the maximum length of the source tables * @param table the information to be melted into our existing table. * @return the thought */ public SusiThought mergeData(JSONArray table1) { JSONArray table0 = this.getData(); while (table0.length() < table1.length()) table0.put(new JSONObject()); for (int i = 0; i < table1.length(); i++) { table0.getJSONObject(i).putAll(table1.getJSONObject(i)); } setData(table0); return this; }
public static JSONObject testJson(boolean ordered) { JSONObject json = new JSONObject(ordered); Map<String, Object> map = new HashMap<>(); map.put("abc", 1); map.put("def", "Hello World"); map.put("ghj", new String[]{"Hello", "World"}); json.putAll(new JSONObject(map)); json.put("eins", 1); json.put("zwei", 2); json.put("drei", 3); json.put("vier", 4); json.put("fuenf", 5); return json; }
private static void setTwitterMetaData(JSONObject metadata, final int startRecord, final int maximumRecords, TwitterTimeline tl, String query, String filter, Query post, JSONObject hits) { // the number of the first record (according to SRU set to 1 for very first) metadata.put("startRecord", startRecord); // number of records within this json result set returned in the api call metadata.put("maximumRecords", maximumRecords); // number of records available in the search cache (so far, may be increased later > hits) metadata.put("count", tl.size()); // number of records in the search index (so far, may be increased later as well) metadata.put("hits", tl.getHits()); if (tl.getOrder() == Order.CREATED_AT) metadata.put("period", tl.period()); metadata.put("query", query); metadata.put("filter", filter); metadata.put("client", post.getClientHost()); metadata.put("time", System.currentTimeMillis() - post.getAccessTime()); metadata.put("servicereduction", post.isDoS_servicereduction() ? "true" : "false"); metadata.putAll(hits); String scraperInfo = tl.getScraperInfo() == null ? "" : tl.getScraperInfo(); metadata.put("scraperInfo", scraperInfo); String index = tl.getResultIndex() == null ? "" : String.valueOf(tl.getResultIndex()); metadata.put("index", index); }
public static JSONObject getNetwork(String screen_name, int maxFollowers, int maxFollowing) throws IOException, TwitterException { JSONObject map = new JSONObject(true); map.putAll(getNetworkerNames(screen_name, maxFollowers, Networker.FOLLOWERS)); map.putAll(getNetworkerNames(screen_name, maxFollowing, Networker.FOLLOWING)); map.remove("screen_name");
public void init(final JSONObject extmap) throws IOException { this.json.putAll(extmap); Date now = new Date(); this.json.put(Field.authentication_first.name(), this.json.has(Field.authentication_first.name()) ? parseDate(this.json.get(Field.authentication_first.name()), now) : now); this.json.put(Field.authentication_latest.name(), this.json.has(Field.authentication_latest.name()) ? parseDate(this.json.get(Field.authentication_latest.name()), now) : now); boolean containsAuth = this.json.has(Field.oauth_token.name()) && this.json.has(Field.oauth_token_secret.name()); if (this.json.has(Field.source_type.name())) { // verify the type try { SourceType st = SourceType.byName((String) this.json.get(Field.source_type.name())); this.json.put(Field.source_type.name(), st.toString()); } catch (IllegalArgumentException e) { throw new IOException(Field.source_type.name() + " contains unknown type " + (String) this.json.get(Field.source_type.name())); } } else { this.json.put(Field.source_type.name(), SourceType.TWITTER); } if (!this.json.has(Field.apps.name()) && !containsAuth) { throw new IOException("account data must either contain authentication details or an apps setting"); } }
message.putAll(mappedProperties);
public Contract mergeData(JSONArray table1) { JSONArray table0 = this.getData(); int t0c = 0; for (int i = 0; i < table1.length(); i++) { JSONObject j1i = table1.getJSONObject(i); while (t0c < table0.length() && anyObjectKeySame(j1i, table0.getJSONObject(t0c))) {t0c++;} if (t0c >= table0.length()) table0.put(new JSONObject(true)); table0.getJSONObject(t0c).putAll(table1.getJSONObject(i)); } setData(table0); return this; }
/** * Merging of data is required during an mind-meld. * To meld two thoughts, we combine their data arrays into one. * The resulting table has at maximum the length of both source tables combined. * @param table the information to be melted into our existing table. * @return the thought */ public SusiThought mergeData(JSONArray table1) { JSONArray table0 = this.getData(); int t0c = 0; for (int i = 0; i < table1.length(); i++) { JSONObject j1i = table1.getJSONObject(i); while (t0c < table0.length() && anyObjectKeySame(j1i, table0.getJSONObject(t0c))) {t0c++;} if (t0c >= table0.length()) table0.put(new JSONObject(true)); table0.getJSONObject(t0c).putAll(table1.getJSONObject(i)); } setData(table0); return this; }
JSONObject jsonObject=new JSONObject(); for(LinkedHashMap<String,Object> map:stringObject){ jsonObject.putAll(map); System.out.println(jsonObject); }
JSONObject json = new JSONObject(); json.putAll(WordMap); String serializedMap = json.toString(); prop.setProperty("wordMap", serializedMap);
Iterator one = (Iterator) friends.find(query).projection("{_id:0}").as(Object.class); while (one.hasNext()) { Map data= new HashMap(); data= (HashMap) one.next(); JSONObject d = new JSONObject(); d.putAll(data); String content=d.toString(); }
Map<String, Object> data = new HashMap<String, Object>(); data.put( "name", "Mars" ); data.put( "age", 32 ); data.put( "city", "NY" ); JSONObject json = new JSONObject(); json.putAll( data ); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().println(json);
if (object instanceof Map){ JSONObject jsonObject = new JSONObject(); jsonObject.putAll((Map)object); ... ... } else if (object instanceof List){ JSONArray jsonArray = new JSONArray(); jsonArray.addAll((List)object); ... ... }
if (object instanceof Map){ JSONObject jsonObject = new JSONObject(); jsonObject.putAll((Map)object); ... ... } else if (object instanceof List){ JSONArray jsonArray = new JSONArray(); jsonArray.addAll((List)object); ... ... }
public JSONArray getJsonObjectOrJsonArray(Object object){ JSONArray jsonArray = new JSONArray(); if (object instanceof Map){ JSONObject jsonObject = new JSONObject(); jsonObject.putAll((Map)object); jsonArray.add(jsonObject); } else if (object instanceof List){ jsonArray.addAll((List)object); } return jsonArray; }