return toString(scratch,0,i); return toString(scratch,0,i); b=new StringBuffer(getStringBufferSize());
/** * @param s String containing JSON object or array. * @return A Map, Object array or primitive array parsed from the JSON. */ public static Object parse(String s) { return __default.parse(new StringSource(s),false); }
buffer.append("null"); else if (object instanceof Convertible) appendJSON(buffer,(Convertible)object); else if (object instanceof Generator) appendJSON(buffer,(Generator)object); else if (object instanceof Map) appendMap(buffer,(Map)object); else if (object instanceof Collection) appendArray(buffer,(Collection)object); else if (object.getClass().isArray()) appendArray(buffer,object); else if (object instanceof Number) appendNumber(buffer,(Number)object); else if (object instanceof Boolean) appendBoolean(buffer,(Boolean)object); else if (object instanceof String) appendString(buffer,(String)object); else Convertor convertor=getConvertor(object.getClass()); if (convertor!=null) appendJSON(buffer,convertor,object); else appendString(buffer,object.toString());
public static String toString(Map object) { StringBuffer buffer=new StringBuffer(__default.getStringBufferSize()); synchronized (buffer) { __default.appendMap(buffer,object); return buffer.toString(); } }
public static String toString(Object[] array) { StringBuffer buffer=new StringBuffer(__default.getStringBufferSize()); synchronized (buffer) { __default.appendArray(buffer,array); return buffer.toString(); } }
public static String toString(Object object) { StringBuffer buffer=new StringBuffer(__default.getStringBufferSize()); synchronized (buffer) { __default.append(buffer,object); return buffer.toString(); } }
/** * Returned information is a JSON representation of a map with * volume name as the key and value is a map of volume attribute * keys to its values */ @Override // DataNodeMXBean public String getVolumeInfo() { Preconditions.checkNotNull(data, "Storage not yet initialized"); return JSON.toString(data.getVolumeInfoMap()); }
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = new PrintWriter(response.getOutputStream()); String format = request.getParameter("format"); Collection<MetricsContext> allContexts = ContextFactory.getFactory().getAllContexts(); if ("json".equals(format)) { // Uses Jetty's built-in JSON support to convert the map into JSON. out.print(new JSON().toJSON(makeMap(allContexts))); } else { printMap(out, makeMap(allContexts)); } out.close(); }
Map map=newMap(); char next=seekTo("\"}",source); String name=parseString(source); seekTo(':',source); source.next(); Object value=contextFor(name).parse(source); map.put(name,value); seekTo(",}",source); next=source.next(); if (next=='}') break; else next=seekTo("\"}",source); return convertTo(c,map);
return newArray(0); case 1: Object array = newArray(1); Array.set(array,0,item); return array; default: return list.toArray(newArray(list.size())); item=contextForArray().parse(source); else if (list==null) item=contextForArray().parse(source); list.add(item); item=null; item=contextForArray().parse(source); list.add(item); item=null;
public String getJSON() { if (_json == null) { JSON json=_pool == null?JSON.getDefault():_pool.getMsgJSON(); StringBuffer buf=new StringBuffer(json.getStringBufferSize()); synchronized(buf) { json.appendMap(buf,this); _json=buf.toString(); } } return _json; }
import JSON; var json = new JSON(); var loader:LoadVars = new LoadVars(); loader.onData = function(data) { trace(json.parse(data).name); // gives : Tom } loader.load('file.json');
@Override public String getSnapshotStats() { Map<String, Object> info = new HashMap<String, Object>(); info.put("SnapshottableDirectories", this.getNumSnapshottableDirs()); info.put("Snapshots", this.getNumSnapshots()); return JSON.toString(info); }
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (!HttpServer2.isInstrumentationAccessAllowed(getServletContext(), request, response)) { return; } String format = request.getParameter("format"); Collection<MetricsContext> allContexts = ContextFactory.getFactory().getAllContexts(); if ("json".equals(format)) { response.setContentType("application/json; charset=utf-8"); PrintWriter out = response.getWriter(); try { // Uses Jetty's built-in JSON support to convert the map into JSON. out.print(new JSON().toJSON(makeMap(allContexts))); } finally { out.close(); } } else { PrintWriter out = response.getWriter(); try { printMap(out, makeMap(allContexts)); } finally { out.close(); } } }
public String getJSON() { if (_json==null) { JSON json=_pool==null?JSON.getDefault():_pool.getMsgJSON(); StringBuffer buf = new StringBuffer(json.getStringBufferSize()); synchronized(buf) { json.appendMap(buf,this); _json=buf.toString(); } } return _json; }
public static JSON fromStringToJSON(String jsonString){ boolean isJsonArray = false; Object obj = null; try { JSONArray jsonArray = new JSONArray(jsonString); Log.d("JSON", jsonArray.toString()); obj = jsonArray; isJsonArray = true; } catch (Throwable t) { Log.e("JSON", "Malformed JSON: \"" + jsonString + "\""); } if (object == null) { try { JSONObject jsonObject = new JSONObject(jsonString); Log.d("JSON", jsonObject.toString()); obj = jsonObject; isJsonArray = false; } catch (Throwable t) { Log.e("JSON", "Malformed JSON: \"" + jsonString + "\""); } } return new JSON(obj, isJsonArray); }
/** Convert Object to JSON * @param object The object to convert * @return The JSON String */ public String toJSON(Object object) { StringBuffer buffer=new StringBuffer(getStringBufferSize()); synchronized (buffer) { append(buffer,object); return buffer.toString(); } }