Json with java hashmap

不羁的心 提交于 2019-12-11 07:02:56

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!