gwt - Why JSONParser doesn't remove the " from keys and values? -
i have following json-string:
{"locale":"de","strings":[{"key":"navigation.search","value":"suchen"}]}
i try parse way:
// parse response text json string json = response.gettext(); window.alert(json); jsonvalue jsonvalue = jsonparser.parselenient("{\"locale\":\"de\",\"strings\":[{\"key\":\"navigation.search\",\"value\":\"suchen\"}]}"); window.alert(jsonvalue.isobject().get("locale").tostring()); jsonarray jsonarray = jsonvalue.isobject().get("strings").isarray(); (int = 0; < jsonarray.size(); i++) { window.alert(jsonarray.get(i).isobject().get("key").isstring() + " -> " + jsonarray.get(i).isobject().get("value").isstring()); }
why there quotes in window.alert(), thought, quotes essential, creating json.
by way, json created json.org java-classes:
printwriter w = new printwriter(system.err); new jsonwriter(w) .object() .key("locale").value("de").key("strings").array().object().key("key").value("navigation.search").key("value").value("suchen").endobject().endarray() .endobject(); w.flush();
i think key use stringvalue method. try:
jsonarray.get(i).isobject().get("value").isstring().stringvalue()
Comments
Post a Comment