Example usage for com.google.gwt.json.client JSONValue isString

List of usage examples for com.google.gwt.json.client JSONValue isString

Introduction

In this page you can find the example usage for com.google.gwt.json.client JSONValue isString.

Prototype

public JSONString isString() 

Source Link

Document

Returns a non-null reference if this JSONValue is really a JSONString.

Usage

From source file:com.extjs.gxt.ui.client.data.JsonReader.java

License:sencha.com license

protected int getTotalCount(JSONObject root) {
    if (modelType.getTotalName() != null) {
        JSONValue v = root.get(modelType.getTotalName());
        if (v != null) {
            if (v.isNumber() != null) {
                return (int) v.isNumber().doubleValue();
            } else if (v.isString() != null) {
                return Integer.parseInt(v.isString().stringValue());
            }//from  w  ww . j  a  v  a 2 s  .c o  m
        }
    }
    return -1;
}

From source file:com.extjs.gxt.ui.client.js.JsonConverter.java

License:sencha.com license

/**
 * Decodes a JSONObject to a map.//from  w ww.j a va  2s  .c om
 * 
 * @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;
}

From source file:com.extjs.gxt.ui.client.js.JsonConverter.java

License:sencha.com license

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);/*from www  . j  ava2  s .com*/
        } 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;
}

From source file:com.github.gilbertotorrezan.gwtcloudinary.client.CloudinaryUploadWidget.java

License:Open Source License

private String getSafeString(JSONValue value) {
    if (value == null) {
        return null;
    }//from www  .ja  va  2  s.  c  om
    JSONString string = value.isString();
    if (string == null) {
        return null;
    }
    return string.stringValue();
}

From source file:com.google.api.explorer.client.parameter.schema.ObjectSchemaEditor.java

License:Apache License

@Override
public void setJSONValue(JSONValue value) {
    JSONObject obj = value.isObject();/*  ww w .j  a v a 2s  .co m*/
    if (obj == null) {
        // If this object came as a json blob, we might have to deserialize it
        JSONString str = value.isString();
        JSONValue parsed = null;
        try {
            parsed = JSONParser.parseStrict(str.stringValue());
        } catch (Exception e) {
            // There was an error parsing, just leave parsed as null
        }
        JSONObject parsedObject = parsed != null ? parsed.isObject() : null;
        if (parsedObject != null) {
            obj = parsed.isObject();
        }
    }

    if (obj != null) {
        // Clear the editor before we start adding the keys back in
        clear();

        // For each key that we are going to map we have to instantiate an
        // appropriate editor type. The {@link #onSelect(String)} function
        // instantiates the proper editor type for the key and binds the new
        // editor to our editor.
        for (String key : obj.keySet()) {
            if (properties.containsKey(key)) {
                SchemaEditor editor = onSelect(key, OPTIONAL_PROPERTY);
                editor.setJSONValue(obj.get(key));
            } else if (additionalPropertiesType != null) {
                SchemaEditor editor = addAdditionalPropertyEditor(key);
                editor.setJSONValue(obj.get(key));
            } else {
                throw new JSONException("JSON object contains unknown key: " + key);
            }
        }
    } else {
        throw new JSONException("Invalid JSON object: " + value.toString());
    }
}

From source file:com.google.appinventor.client.explorer.commands.WaitForBuildResultCommand.java

License:Open Source License

private static String extractFormName(RpcResult result) {
    String extraString = result.getExtra();
    if (extraString != null) {
        JSONValue extraJSONValue = JSONParser.parseStrict(extraString);
        JSONObject extraJSONObject = extraJSONValue.isObject();
        if (extraJSONObject != null) {
            JSONValue formNameJSONValue = extraJSONObject.get("formName");
            if (formNameJSONValue != null) {
                JSONString formNameJSONString = formNameJSONValue.isString();
                if (formNameJSONString != null) {
                    return formNameJSONString.stringValue();
                }/*from   ww w. jav a2  s .com*/
            }
        }
    }
    return "Screen1";
}

From source file:com.google.appinventor.client.wizards.TemplateUploadWizard.java

License:Open Source License

/**
 * Sets the dynamic template Urls from a jsonStr.  This method is
 * called during start up where jsonStr is retrieved from User
 * settings./*from w ww. ja  v  a  2s  .com*/
 *
 * @param jsonStr
 */
public static void setStoredTemplateUrls(String jsonStr) {
    if (jsonStr == null || jsonStr.length() == 0)
        return;
    JSONValue jsonVal = JSONParser.parseLenient(jsonStr);
    JSONArray jsonArr = jsonVal.isArray();
    for (int i = 0; i < jsonArr.size(); i++) {
        JSONValue value = jsonArr.get(i);
        JSONString str = value.isString();
        dynamicTemplateUrls.add(str.stringValue());
    }
}

From source file:com.google.debugging.sourcemap.SourceMapObject.java

License:Apache License

private static String getStringOrNull(JSONValue value) {
    if (value == null) {
        return null;
    }// w  ww  .  ja  va2 s.  c om
    JSONString string = value.isString();
    if (string == null) {
        return null;
    }
    return string.stringValue();
}

From source file:com.google.gerrit.client.rpc.RestApi.java

License:Apache License

@SuppressWarnings("unchecked")
private static <T extends JavaScriptObject> T cast(JSONValue val) {
    if (val.isObject() != null) {
        return (T) val.isObject().getJavaScriptObject();
    } else if (val.isArray() != null) {
        return (T) val.isArray().getJavaScriptObject();
    } else if (val.isString() != null) {
        return (T) NativeString.wrap(val.isString().stringValue());
    } else if (val.isNull() != null) {
        return null;
    } else {//w ww. j  ava  2s .  c o m
        throw new JSONException("unsupported JSON type");
    }
}

From source file:com.google.gson.JsonElement.java

License:Apache License

static JsonElement wrap(JSONValue value) {
    if (value == null)
        return null;
    if (value.isNull() != null)
        return JsonNull.createJsonNull();
    if (value.isBoolean() != null || value.isNumber() != null || value.isString() != null)
        return new JsonPrimitive(value);
    if (value.isObject() != null)
        return new JsonObject(value.isObject());
    if (value.isArray() != null)
        return new JsonArray(value.isArray());

    throw new IllegalArgumentException();
}