1

I have hashmap object,

Map testData=new HashMap();
testData.put("test","test1");

I am able to convert this map using json file with Gson library. I know how to get that data using jQuery getJSON.

My question is: how to display both key and value pairs?

9
  • Are you asking how to convert a Map to JSON, so you can pass it to jQuery? Commented Mar 10, 2011 at 15:34
  • Could you please provide more detail? Do you have the http connection between server and client already in place? Commented Mar 10, 2011 at 15:47
  • No,I updated my question Commented Mar 10, 2011 at 16:39
  • Ah, I think I understand. Are you asking how to print both the key and the value from each entry to an HTML page using jQuery? Commented Mar 10, 2011 at 17:03
  • @Chris:Yes,i know with using .each we can display.i dont have any item to iterate to display. Commented Mar 10, 2011 at 17:13

1 Answer 1

3

What about using gson on the server side, and use jQuery's .getJSON on the client-side?

EDIT: added a for-each example according to your changed question, try it here: http://jsfiddle.net/5gEYf/

var response =  {"test": "test1"};
$.each(response, function(key, value) { 
    alert(key + ' -> ' + value); 
});

EDIT:

I stumbled upon this two year old answer of mine, and like to add that I would use Jackson for JSON de- / serialization in Java nowadays.

Sign up to request clarification or add additional context in comments.

1 Comment

There's also Douglas Crockford's reference Java implementation. See json.org/java and github.com/douglascrockford/JSON-java

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.