2

With GWT, how would I go about looping through a JSON object or array, which has been returned via a JSNI method, that I could also extract both name and value pairs per loop?

1 Answer 1

3

Are you using JavaScriptOverlay types or JSONObject like types?

So in case of JSONObject like types and assuming data is of type JSONObject you can do following:

json_string = "{'data':{'key':'test','key2':'test3','key3':'test3'}}"
JSONObject json_data  = JSONParser.parseLenient(json_string);
JSONObject data = json_data.get("data").isObject();
Set<String> keys = data.keySet();
for (String key : keys) 
{
   String value = data.get(key).isString().stringValue();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.