Hi all...
Has someone addressed the performance problem on parsing large JSON files?

I created one Wrapper to do a "latter bind"...


public class JSONMap implements Map {
private JSONObject wrappedJSONObject;
 public JSONMap(JSONObject jsonObject) {
if (jsonObject == null) {
throw new WrongUseException("Invalid JSONObject");
}
 this.wrappedJSONObject = jsonObject;
}
 public void clear() {
throw new UnsupportedOperationException();
}
 public boolean containsKey(Object key) {
throw new UnsupportedOperationException();
}

public boolean containsValue(Object value) {
throw new UnsupportedOperationException();
}

public Set entrySet() {
throw new UnsupportedOperationException();
}
 protected String getKey(Object key) {
String keyValue;
 if (key instanceof String) {
keyValue = (String)key;
} else {
keyValue = key.toString();
}
 return keyValue;
}

public Object get(Object key) {
JSONArray jsonArray;
JSONBoolean jsonbBoolean;
JSONNumber jsonNumber;
JSONObject jsonObject;
JSONString jsonString;
JSONValue jsonValue = wrappedJSONObject.get(getKey(key));
 if ((jsonArray = jsonValue.isArray()) != null) {
return new JSONList(jsonArray);
} else if ((jsonbBoolean = jsonValue.isBoolean()) != null) {
return new Boolean(jsonbBoolean.booleanValue());
} else if ((jsonNumber = jsonValue.isNumber()) != null) {
return new Double(jsonNumber.doubleValue());
} else if ((jsonObject = jsonValue.isObject()) != null) {
return new JSONMap(jsonObject);
} else if ((jsonString = jsonValue.isString()) != null) {
return jsonString.stringValue();
} else {
return null;
}
}
 public JSONMap getMap(String key) {
return new JSONMap(wrappedJSONObject.get(key).isObject());
}
 public String getString(String key) {
return wrappedJSONObject.get(key).isString().stringValue();
}
 public Double getDouble(String key) {
return new Double(wrappedJSONObject.get(key).isNumber().doubleValue());
}
 public JSONList getList(String key) {
return new JSONList(wrappedJSONObject.get(key).isArray());
}

public boolean isEmpty() {
return wrappedJSONObject.size() == 0;
}

public Set keySet() {
return wrappedJSONObject.keySet();
}

public Object put(Object arg0, Object arg1) {
throw new UnsupportedOperationException();
}

public void putAll(Map arg0) {
throw new UnsupportedOperationException();
}

public Object remove(Object key) {
throw new UnsupportedOperationException();
}

public int size() {
return wrappedJSONObject.size();
}

public Collection values() {
throw new UnsupportedOperationException();
}
}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to