List of usage examples for com.google.gwt.json.client JSONValue isString
public JSONString isString()
From source file:org.sonatype.nexus.gwt.ui.client.data.JSONResourceParser.java
License:Open Source License
private Object toObject(JSONValue json) { Object obj = null;/*from ww w . j av a2 s . c o m*/ if (json instanceof JSONBoolean) { obj = Boolean.valueOf(json.isBoolean().booleanValue()); } else if (json instanceof JSONString) { obj = json.isString().stringValue(); } else if (json instanceof JSONNumber) { obj = new Double(json.isNumber().doubleValue()); } return obj; }
From source file:org.sonatype.nexus.gwt.ui.client.table.JSONArrayTableModel.java
License:Open Source License
public Object getCell(int rowIndex, int colIndex) { JSONObject obj = (JSONObject) getRow(rowIndex); JSONValue val = JSONUtil.getValue(obj, props[colIndex]); if (val != null) { if (val.isString() != null) { return val.isString().stringValue(); } else if (val.isBoolean() != null) { return Boolean.valueOf(val.isBoolean().booleanValue()); } else if (val.isNumber() != null) { return new Double(val.isNumber().doubleValue()); } else if (val.isNull() != null) { return null; } else {//from w ww .ja v a2s.com return val; } } return null; }
From source file:org.spiffyui.client.JSONUtil.java
License:Apache License
/** * Get a string from the JSON object or defaultValue if it doesn't exist or * isn't a string// ww w . j a v a 2 s .com * * @param obj the object with the value * @param key the key for the object * @param defaultValue the default value to return if the key could not be found * * @return the value or the defaultValue if it could not be decoded */ public static String getStringValue(JSONObject obj, String key, String defaultValue) { if (!obj.containsKey(key)) { return defaultValue; } JSONValue v = obj.get(key); if (v != null) { JSONString s = v.isString(); if (s != null) { return s.stringValue(); } } return defaultValue; }
From source file:org.spiffyui.client.JSONUtil.java
License:Apache License
/** * Get a string from the JSON object or defaultValue if it doesn't exist or * isn't a string//from w w w. j a v a 2 s. co m * * @param obj the object with the value * @param key the key for the object * @param defaultValue the default value to return if the key could not be found * * @return the value or the defaultValue if it could not be decoded */ public static String getStringValueIgnoreCase(JSONObject obj, String key, String defaultValue) { JSONValue v = obj.get(key); if (v == null) { String lowerKey = key.toLowerCase(); for (String k : obj.keySet()) { if (lowerKey.equals(k.toLowerCase())) { v = obj.get(k); break; } } } if (v != null) { JSONString s = v.isString(); if (s != null) { return s.stringValue(); } } return defaultValue; }
From source file:org.spiffyui.client.JSONUtil.java
License:Apache License
/** * Get a boolean from the JSON object or defaultValue if it doesn't exist or * isn't a boolean//from w ww . j ava 2 s .co m * * @param obj the object with the value * @param key the key for the object * @param defaultValue the default value if the key can not be found * * @return the value or false it could not be decoded */ public static boolean getBooleanValue(JSONObject obj, String key, boolean defaultValue) { if (!obj.containsKey(key)) { return defaultValue; } JSONValue v = obj.get(key); if (v != null) { JSONBoolean b = v.isBoolean(); if (b != null) { return b.booleanValue(); } else { JSONString s = v.isString(); if (s != null) { return Boolean.parseBoolean(s.stringValue()); } } } return defaultValue; }
From source file:org.talend.mdm.webapp.browserecords.client.rest.ExplainRestServiceHandler.java
License:Open Source License
private String getStringValue(JSONValue jsonValue) { String value = null;// ww w . j av a2 s . c om if (jsonValue != null) { if (jsonValue.isString() != null) { value = jsonValue.isString().toString().replaceAll("\"", ""); //$NON-NLS-1$ //$NON-NLS-2$ } else if (jsonValue.isBoolean() != null) { value = jsonValue.isBoolean().toString(); } else if (jsonValue.isNumber() != null) { value = jsonValue.isNumber().toString(); } } return value; }
From source file:org.thechiselgroup.biomixer.client.json.JsJsonParser.java
License:Apache License
@Override public String asString(Object jsonValue) { if (null == jsonValue) { return null; }/* w ww . ja v a 2 s . c om*/ JSONValue node = (JSONValue) jsonValue; if (node.isString() != null) { return node.isString().stringValue(); } if (node.isNumber() != null) { return node.isNumber().toString(); } return null; }
From source file:org.utgenome.gwt.utgb.client.db.datatype.DataTypeBase.java
License:Apache License
public String toString(JSONValue value) { JSONString s = value.isString(); if (s != null) return s.stringValue(); else//from www . ja va2s . c o m return value.toString(); }
From source file:org.utgenome.gwt.utgb.client.util.JSONUtil.java
License:Apache License
/** * Get a string value (without double quotation) of JSONString, or other JSON types. * /*from w w w .j a v a2 s . c o m*/ * @param value * @return */ public static String toStringValue(JSONValue value) { if (value == null) return ""; JSONString str = value.isString(); if (str != null) return str.stringValue(); else return value.toString(); }
From source file:org.waveprotocol.wave.client.gadget.renderer.GadgetMetadata.java
License:Apache License
/** * Helper function to extract a string value from given JSON object. * * @param json JSON object to extract the value from. * @param key key of the value to extract. * @return the string object extracted from JSON (can be null if the value * does not exist or is invalid. *///from w w w .j av a 2 s .c om private static String getJsonStringValue(JSONObject json, String key) { JSONValue value = json.get(key); JSONString string = (value == null) ? null : value.isString(); if (string != null) { return string.stringValue(); } else { return null; } }