Android JSONTokener - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android JSONTokener class.

This code example shows how to use the following methods:nextValue
            HttpServletRequest request, JSONObject engineConfig) throws Exception {
         
        String columnName = request.getParameter("columnName");
        String configString = request.getParameter("config");
         
        JSONTokener t = new JSONTokener(configString);
        JSONObject config = (JSONObject) t.nextValue();
         
        return new ReconOperation(engineConfig, columnName, ReconConfig.reconstruct(config));
    } 
} 
8
CodeRank
This code example shows how to use the following methods:nextValue
    // Returns either a JSONObject or JSONArray representation of the 'key' property of 'jsonObject'. 
    public static Object getStringPropertyAsJSON(JSONObject jsonObject, String key, String nonJSONPropertyKey)
            throws JSONException { 
        Object value = jsonObject.opt(key);
        if (value != null && value instanceof String) {
            JSONTokener tokener = new JSONTokener((String) value);
            value = tokener.nextValue();
        } 
 
        if (value != null && !(value instanceof JSONObject || value instanceof JSONArray)) {
            if (nonJSONPropertyKey != null) {
                // Facebook sometimes gives us back a non-JSON value such as 
                // literal "true" or "false" as a result. 
                // If we got something like that, we present it to the caller as 
                // a GraphObject with a single 
                // property. We only do this if the caller wants that behavior. 
                jsonObject = new JSONObject();
                jsonObject.putOpt(nonJSONPropertyKey, value);
                return jsonObject;
            } else { 
8
CodeRank
This code example shows how to use the following methods:nextValue
 
    static public JSONObject evaluateJsonStringToObject(String s) throws JSONException {
        if( s == null ) {
            throw new IllegalArgumentException("parameter 's' should not be null");
        } 
        JSONTokener t = new JSONTokener(s);
        Object o = t.nextValue();
        if (o instanceof JSONObject) {
            return (JSONObject) o;
        } else { 
            throw new JSONException(s + " couldn't be parsed as JSON object");
        } 
    } 
 
    static public JSONArray evaluateJsonStringToArray(String s) throws JSONException {
        JSONTokener t = new JSONTokener(s);
        Object o = t.nextValue();
        if (o instanceof JSONArray) {
            return (JSONArray) o;
        } else { 
7
CodeRank
This code example shows how to use the following methods:nextValue
    // Returns either a JSONObject or JSONArray representation of the 'key' property of 'jsonObject'. 
    public static Object getStringPropertyAsJSON(JSONObject jsonObject, String key, String nonJSONPropertyKey)
            throws JSONException { 
        Object value = jsonObject.opt(key);
        if (value != null && value instanceof String) {
            JSONTokener tokener = new JSONTokener((String) value);
            value = tokener.nextValue();
        } 
 
        if (value != null && !(value instanceof JSONObject || value instanceof JSONArray)) {
            if (nonJSONPropertyKey != null) {
                // Facebook sometimes gives us back a non-JSON value such as 
                // literal "true" or "false" as a result. 
                // If we got something like that, we present it to the caller as 
                // a GraphObject with a single 
                // property. We only do this if the caller wants that behavior. 
                jsonObject = new JSONObject();
                jsonObject.putOpt(nonJSONPropertyKey, value);
                return jsonObject;
            } else { 
7
CodeRank
This code example shows how to use the following methods:
 
    @Override 
    public Object toJSON(InputStream is) throws IOException {
        try { 
            InputStreamReader r = new InputStreamReader(is, "UTF-8");
            JSONTokener t = new JSONTokener(r);
            return new JSONObject(t);
        } catch (JSONException ex) {
            throw new IOException(ex);
        } 
    } 
 
    @Override 
    public void loadJSON(JSONCall call) {
        throw new UnsupportedOperationException();
    } 
} 
6
CodeRank
This code example shows how to use the following methods:
    public JSONTokener getJsonTokener() throws JSONException {
        if (this.jsonValue != null) {
            return (JSONTokener) this.jsonValue;
        } 
 
        return new JSONTokener(getJsonText());
    } 
 
    @Override 
    public long getSize() { 
        if (this.jsonRepresentation != null) {
            return this.jsonRepresentation.getSize();
        } 
        return super.getSize(); 
    } 
 
    /** 
     *  
     * @param jsonObject 
     */ 
6
CodeRank
This code example shows how to use the following methods:back, next
        return tree.getResult();
    } 
 
    private static void buildJsonX(TreeWriter tree, JSONTokener jt) {
        try { 
            char ch = jt.next();
            jt.back();
 
            if (ch == '{') {
                tree.addStartElement(j_object);
                tree.startContent();
                buildJsonXPairs(tree, new JSONObject(jt));
            } else { 
                tree.addStartElement(j_array);
                buildJsonXArray(tree, new JSONArray(jt));
            } 
        } catch (JSONException je) {
            throw new XProcException(je);
        } 
 
6
CodeRank
This code example shows how to use the following methods:
			IOException { 
 
 
		MetaData md;
		try { 
			md = new MetaData(new JSONTokener(new InputStreamReader(is, UTF8)));
		} catch (JSONException e) {
			throw new ResourceParseException(e);
		} 
		return new WARCJSONMetaDataResource(md, container);
	} 
 
} 
5
CodeRank
This code example shows how to use the following methods:nextValue
    /** {@inheritDoc} */ 
    @Override 
    public void doPut(final HttpServletRequest request, final HttpServletResponse response)
            throws ServletException, IOException { 
        final JSONWriter writer = createResponseWriter(response);
        final JSONTokener tokener = new JSONTokener(request.getReader());
        try { 
            put(request, tokener.nextValue(), writer);
        } 
        catch (Exception error){
            error.printStackTrace();
            throw new ServletException(error);
        } 
    } 
 
    /** 
     * Creates a JSON response writer and sets the content-type accordingly 
     * @param response The response 
     * @return The response writer 
     * @throws IOException 
6
CodeRank
This code example shows how to use the following methods:nextValue
     * Parses JSON and creates an object. 
     * @return The resulting object which may be a List,  
     * Map, Number, String, Boolean, or null 
     */ 
    public Object read() throws JSONException {
        JSONTokener tk = new JSONTokener(json);
        try { 
            return readSubObject(tk.nextValue());
        } catch(org.json.JSONException e) {
            throw new JSONException(e.toString());
        } 
    } 
 
    /** 
     * Assumes that a JSON array will be read.  Returns 
     * the resulting array as a list. 
     */ 
    public List<?> readArray() throws JSONException {
        Object o = read();
        try { 
6
CodeRank

Related Android JSONTokener Questions & Answers:

See Code Examples for Android JSONTokener Methods: