Json用java hashmap [英] Json with java hashmap
问题描述
我有hashmap对象,
Map testData = new HashMap();
testData.put(test,test1);
我可以使用json文件和Gson库转换这张地图。我知道如何使用jQuery getJSON获取数据。
我的问题是:如何显示键和值对?
如何使用 gson 在服务器端,并在客户端使用jQuery的 .getJSON ?
编辑:根据您更改的问题添加for-each示例,请在此处尝试: http://jsfiddle.net/5gEYf/
var response = {test:test1 };
$ .each(response,function(key,value){
alert(key +' - >'+ value);
});
编辑:
我偶然发现了这个两年前的答案,并且想补充说我会使用 Jackson 现在在Java中用于JSON de- /序列化。
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?
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.
这篇关于Json用java hashmap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!