if ((jsonObject = jsonValue.isObject()) == null) { Window.alert("Error parsing the JSON"); if ((jsonArray = jsonValue.isArray()) == null) { Window.alert("Error parsing the JSON"); if ((jsonObject = jsonValue.isObject()) == null) { Window.alert("Error parsing the JSON"); Window.alert(jsonString.stringValue()); // Finally!
@Override public void onSuccess(LogAppenderDto key) { JSONObject json = (JSONObject) JSONParser.parseLenient(key.getJsonConfiguration()); json.put("minLogSchemaVersion", new JSONNumber(key.getMinLogSchemaVersion())); json.put("maxLogSchemaVersion", new JSONNumber(key.getMaxLogSchemaVersion())); json.put("pluginTypeName", new JSONString(key.getPluginTypeName())); json.put("pluginClassName", new JSONString(key.getPluginClassName())); JSONArray headersStructure = new JSONArray(); for (LogHeaderStructureDto header : key.getHeaderStructure()) { headersStructure.set(headersStructure.size(), new JSONString(header.getValue())); } json.put("headerStructure", headersStructure); ServletHelper.downloadJsonFile(json.toString(), key.getPluginTypeName() + ".json"); } };
public String getColumnValue( String columnName ) { for( int i=0; i<row.size(); i++ ) { JSONObject cellJson = row.get( i ).isObject(); if( cellJson.get( "column" ).isString().stringValue().equals( columnName ) ) return cellJson.get( "value" ).isString().stringValue(); } return null; }
public JSONObject toJsonObjectInt(boolean copyJsons) { JSONObject result = new JSONObject(); JSONValue stateOut = (this.state == null) ? JSONNull.getInstance() : new JSONString(this.state.name()); result.put("state", stateOut); JSONValue outputOut = (this.output == null) ? JSONNull.getInstance() : new JSONString(this.output); result.put("output", outputOut); return result; }
public static ReImportMavenProjectsCommandParametersDto fromJson(JSONValue jsonVal) { if (jsonVal == null) { return null; } JSONObject json= jsonVal.isObject(); ReImportMavenProjectsCommandParametersDto result= new ReImportMavenProjectsCommandParametersDto(); JSONValue jsonprojectsToUpdateJson = json.get("projectsToUpdate"); if (jsonprojectsToUpdateJson != null && !(jsonprojectsToUpdateJson.isNull() != null)) { ArrayList<java.lang.String> jsonprojectsToUpdateVal= new ArrayList<java.lang.String>(); JSONArray jsonprojectsToUpdateVala = jsonprojectsToUpdateJson.isArray(); for(int jsonprojectsToUpdateValai= 0; jsonprojectsToUpdateValai < jsonprojectsToUpdateVala.size(); jsonprojectsToUpdateValai++) { java.lang.String jsonprojectsToUpdateValaX = jsonprojectsToUpdateVala.get(jsonprojectsToUpdateValai).isString().stringValue();; jsonprojectsToUpdateVal.add(jsonprojectsToUpdateValaX); } result.setProjectsToUpdate((java.util.List<java.lang.String>)jsonprojectsToUpdateVal); } return result; } }
public void got(final JSONValue json) { final JSONObject bd = json.isObject(); final JSONString shortrev = bd.get("short_revision").isString(); final JSONString status = bd.get("repo_status").isString(); final JSONNumber stamp = bd.get("timestamp").isNumber(); final JSONString user = bd.get("user").isString(); final JSONString host = bd.get("host").isString(); final JSONString repo = bd.get("repo").isString(); build_data.setHTML( "OpenTSDB built from revision " + shortrev.stringValue() + " in a " + status.stringValue() + " state<br/>" + "Built on " + new Date((long) (stamp.doubleValue() * 1000)) + " by " + user.stringValue() + '@' + host.stringValue() + ':' + repo.stringValue() ); } });
public JSONValue toJsonElement() { JSONObject result = new JSONObject(); if (getProjectsToUpdate() == null) { setProjectsToUpdate((java.util.List<java.lang.String>)null); } else { JSONArray projectsToUpdateVal = new JSONArray(); for (java.lang.String projectsToUpdateValX : getProjectsToUpdate()) { JSONValue projectsToUpdateValY = projectsToUpdateValX == null ? JSONNull.getInstance() : new JSONString(projectsToUpdateValX);; projectsToUpdateVal.set(projectsToUpdateVal.size(), projectsToUpdateValY); } result.put("projectsToUpdate", projectsToUpdateVal); } return result; }
public static JSONValue And( JSONValue... operands ) { JSONObject obj = new JSONObject(); obj.put( "op", new JSONString( "and" ) ); JSONArray ops = new JSONArray(); for( int i = 0; i < operands.length; i++ ) ops.set( i, operands[i] ); obj.put( "ops", ops ); return obj; }
@Override public Object decode(JSONValue value) throws JsonEncoderDecoder.DecodingException { if (value instanceof JSONNumber) { return ((JSONNumber) value).doubleValue(); } else if (value instanceof JSONBoolean) { return ((JSONBoolean) value).booleanValue(); } else if (value instanceof JSONString) { return ((JSONString) value).stringValue(); } else if (value instanceof JSONArray) { JSONArray array = value.isArray(); List<Object> list = new ArrayList<Object>(array.size()); for (int ct = 0; ct < array.size(); ct++) { list.add(decode(array.get(ct))); } return list; } else if (value instanceof JSONObject) { JSONObject object = value.isObject(); Map<String, Object> map = new HashMap<String, Object>(); for (String key : object.keySet()) { map.put(key, decode(object.get(key))); } return map; } else { return null; } }
@Override public Object deserialize(final JSONValue jsonValue) { if (jsonValue == null || jsonValue.isNull() != null) { return null; final JSONString jsonString = jsonValue.isString(); if (jsonString != null) { return jsonString.stringValue(); final JSONNumber jsonNumber = jsonValue.isNumber(); if (jsonNumber != null) { return jsonNumber.doubleValue(); final JSONBoolean jsonBoolean = jsonValue.isBoolean(); if (jsonBoolean != null) { return jsonBoolean.booleanValue(); if (jsonArray != null) { final List<Object> list = new ArrayList<Object>(); for (int i = 0; i < jsonArray.size(); i++) { list.add(deserialize(jsonArray.get(i))); if (jsonObject != null) { final Map<String, Object> map = new HashMap<String, Object>(); for (String key : jsonObject.keySet()) { map.put(key, deserialize(jsonObject.get(key)));
public static FileStructureCommandParametersDto fromJson(JSONValue jsonVal) { if (jsonVal == null) { return null; } JSONObject json= jsonVal.isObject(); FileStructureCommandParametersDto result= new FileStructureCommandParametersDto(); JSONValue jsonshowInheritedJson = json.get("showInherited"); if (jsonshowInheritedJson != null && !(jsonshowInheritedJson.isNull() != null)) { boolean jsonshowInheritedVal = jsonshowInheritedJson.isBoolean().booleanValue(); result.setShowInherited((boolean)jsonshowInheritedVal); } JSONValue jsonuriJson = json.get("uri"); if (jsonuriJson != null && !(jsonuriJson.isNull() != null)) { java.lang.String jsonuriVal = jsonuriJson.isString().stringValue();; result.setUri((java.lang.String)jsonuriVal); } return result; } }
public static void dispatchJSON(JavaScriptObject jsonObj, JSONHandler handler) { JSONObject obj = new JSONObject(jsonObj); if (obj.isObject() != null) { if (obj.containsKey("err_code")) { handler.onError(new Double(obj.get("err_code").isNumber().doubleValue()).intValue(), obj.get("err_msg").isString().stringValue()); return; } } handler.onResponse(jsonObj); }
@Override public JSONValue encode(Object value) throws JsonEncoderDecoder.EncodingException { if (value instanceof Number) { return new JSONNumber(((Number) value).doubleValue()); } else if (value instanceof Boolean) { return JSONBoolean.getInstance((Boolean) value); } else if (value instanceof Iterable) { JSONArray array = new JSONArray(); int ct = 0; for (Object v : (Iterable<?>) value) { array.set(ct++, encode(v)); } return array; } else if (value instanceof Map) { JSONObject object = new JSONObject(); for (Map.Entry<?, ?> entry : ((Map<?, ?>) value).entrySet()) { object.put(entry.getKey().toString(), encode(entry.getValue())); } return object; } else if (value == null) { return JSONNull.getInstance(); } else { return new JSONString(value.toString()); } }
protected static List<Object> decodeToList(JSONArray array) { List<Object> list = new ArrayList<Object>(); for (int i = 0; i < array.size(); i++) { JSONValue v = array.get(i); if (v.isObject() != null) { list.add(decode(v.isObject())); } else if (v.isArray() != null) { list.add(decodeToList(v.isArray())); } else if (v.isNull() != null) { list.add(null); } else if (v.isNumber() != null) { list.add(v.isNumber().doubleValue()); } else if (v.isBoolean() != null) { list.add(v.isBoolean().booleanValue()); } else if (v.isString() != null) { list.add(decodeValue(v.isString().stringValue())); } } return list; }
public static void fire(HasDataSelectionEventHandlers source, Object sender, JavaScriptObject data) { DataSelectionEvent event = new DataSelectionEvent(sender); JSONObject array = new JSONObject(data); event.series = new LinkedList<Series>(); for(String key : array.keySet()){ JSONObject obj = array.get(key).isObject(); if(obj != null){ Series series1 = JavaScriptObject.createObject().cast(); series1.setValue(obj.get("value").isNumber().doubleValue()); series1.setColor(obj.get("fillColor").isString().stringValue()); event.series.add(series1); } } source.fireEvent(event); }
/** * Decodes a JSONObject to a map. * * @param jso the JSONObject * @return the map */ public static Map<String, Object> decode(JSONObject jso) { Map<String, Object> map = new FastMap<Object>(); for (String key : jso.keySet()) { JSONValue j = jso.get(key); if (j.isObject() != null) { map.put(key, decode(j.isObject())); } else if (j.isArray() != null) { map.put(key, decodeToList(j.isArray())); } else if (j.isBoolean() != null) { map.put(key, j.isBoolean().booleanValue()); } else if (j.isString() != null) { map.put(key, decodeValue(j.isString().stringValue())); } } return map; }
private static ColumnView parseColumn(int rowsCount, JSONObject jsonColumn) { String storage = jsonColumn.get("storage").isString().stringValue(); String typeName = jsonColumn.get("type").isString().stringValue(); ColumnType type = ColumnType.valueOf(typeName); return new ColumnArrayView(type, jsonColumn.get("values").isArray().getJavaScriptObject()); case "empty": return new EmptyColumnView(type, rowsCount); return new ConstantColumnView(rowsCount, null); } else { return new ConstantColumnView(rowsCount, jsonString.stringValue()); return new ConstantColumnView(rowsCount, Double.NaN); } else { return new ConstantColumnView(rowsCount, jsonNumber.doubleValue()); return ConstantColumnView.nullBoolean(rowsCount); } else { return new ConstantColumnView(rowsCount, jsonValue.isBoolean().booleanValue());
public void addCell( String columnName, String value ) { JSONObject cell = new JSONObject(); cell.put( "column", new JSONString( columnName ) ); cell.put( "value", new JSONString( value ) ); row.set( row.size(), cell ); }
private Object fromJsonValue(JSONValue elem) { if (elem.isString() != null) { return elem.isString().stringValue(); } else if (elem.isNumber() != null) { return elem.isNumber().doubleValue(); } else if (elem.isArray() != null) { return asList(elem.isArray()); } else if (elem.isNull() != null) { return null; } else if (elem.isObject() != null) { return asMap(elem.isObject()); } else { return ""; } } }
private static JSONObject logRecordAsJsonObject(LogRecord lr) { JSONObject obj = new JSONObject(); obj.put("level", getJsonString(lr.getLevel().toString())); obj.put("loggerName", getJsonString(lr.getLoggerName())); obj.put("msg", getJsonString(lr.getMessage())); obj.put("timestamp", new JSONString("" + lr.getMillis())); obj.put("thrown", throwableAsJsonObject(lr.getThrown())); return obj; }