No al cierre de webs
Permalink: http://www.treeweb.es/u/434/ 09/11/2010

Decodificar JSON

Primero debemos heredar la librería JSON de Google, para ello, vamos al archivo src/nombre_proyecto/nombre_proyecto.gwt.xml y añadimos la siguiente línea al fichero XML:
<inherits name="com.google.gwt.json.JSON" />
Ahora ya estamos listos para poder utilizar las bondades de la 'fabulosa' librería. Un ejemplo de uso:
private void procesarRespuesta(String json_string) { JSONValue obj = JSONParser.parse(json_string); com.google.gwt.json.client.JSONObject lista = obj.isObject(); Object[] w = lista.keySet().toArray(); for (int i = 0; i<w.length; i++) { if (w[i].toString() == "session") { procesarSession(lista.get(w[i].toString())); } else if (w[i].toString() == "timestamp") { procesarTimestamp(lista.get(w[i].toString())); } else if (w[i].toString() == "user_type") { procesarUserType(lista.get(w[i].toString())); } } } private void procesarSession(JSONValue json) { if (json.isString()!=null) _session = json.isString().stringValue(); } private void procesarTimestamp(JSONValue json) { if (json.isString()!=null) _timestamp = json.isString().stringValue(); } private void procesarUserType(JSONValue json) { if (json.isString()!=null) _user_type = json.isString().stringValue(); }