问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/5261884/json-with-java-hashmap