FileDocCategorySizeDatePackage
JSONParser.javaAPI DocExample5197Wed Jul 26 13:34:14 BST 2006com.oreilly.ajax.client

JSONParser

public class JSONParser extends Object
This class converts a JSON object encoded as a string into the corresponding set of JSONValue derived objects. Internally, this class uses JSNI to interact with JavaScript directly.

Fields Summary
Constructors Summary
Methods Summary
private static JSONArraybuildArray()

    JSONArray array = new JSONArray();
    return array;
  
private static JSONBooleanbuildBoolean(boolean value)

    return new JSONBoolean(value);
  
private static JSONNumberbuildNumber(java.lang.String value)

    return new JSONNumber(value);
  
private static native JSONObjectbuildObject(com.google.gwt.core.client.JavaScriptObject jsObject)

private static JSONStringbuildString(java.lang.String value)

    return new JSONString(value);
  
private static native JSONValuebuildValue(com.google.gwt.core.client.JavaScriptObject jsValue)

private static JSONObjectcreateJSONObject()

    return new JSONObject();
  
private static native com.google.gwt.core.client.JavaScriptObjectevaluate(java.lang.String jsonString)

public static JSONObjectparse(java.lang.String jsonString)
Given a jsonString return the JSONObject representation. This method will throw a JSONException if the string is invalid.

param
jsonString
return
a JSONObject that has been built by parsing the JSON string.

    // Create a JavaScriptObject from the JSON string
    //
    try {
      JavaScriptObject jsonObject = evaluate(jsonString);
    
      return buildObject(jsonObject);
      
    } catch (JavaScriptException ex) { 
      throw new JSONException(ex);
      
    }
  
private static voidraiseJSONException()

    throw new JSONException();
  
public static java.lang.StringtoString(JSONValue value)

    return value.toString();