我正在从以下代码中获取列表<条目><字符串,整数>>作为json响应条目>
@RequestMapping(value="/responseString", method = RequestMethod.POST)
@ResponseBody
public String responseString(HttpServletRequest request) throws Exception {
try{
List<Entry<String, Integer>> result = Util.topNKeys(Util.getvalues(resultSet, 2), 3);
return JSONSerializer.toJSON(result).toString();
} catch(Exception e) {
}}
通过调用 Ajax 调用,
$.ajax({
type: 'POST',
url: '<%=request.
getContextPath()%>/responseString',
data: ({batchId: batchId, clientId:clientId}),
success: function(data) {
var listEntryData = jQuery.parseJSON(data);
error: function(xhr, textStatus, error){
alert("Error occured. Please try after some time.");
}
});
我得到下面的回复
[it help me=1, is a good=1, how to spend=2, like myself it=3, my mo ey=4, people like myself=5, me to understa=6, understa d how=7]
我想像下面这样显示它
it help me: 1 how to spend: 2 my mo ey=4 me to understa: 6
is a good: 1 like myself it: 3 people like myself: 5 understa d how: 7
显示内容必须:
1.(人口必须从上到下垂直,左对齐
2.(根据内容,它必须有4列和行,即如果数据计数 14. 它应该有 4 行。
请帮我解决这个问题。
我建议您尝试getJSON方法来检索json数据。就这样做...
$.getJSON("<%=request.getContextPath()%>/responseString",{batchId: batclientId:clientId},function(data){
if (data){
$.each(data , function(){
$("#block").append('<div class="col-md-3">'+this['key1']+' : '+this['key2']+'</div>');
});
}
else{
alert("Error occured. Please try after some time.");
}
});
并将 ID 为 #block 和类 .row 的div 放在要显示这些数据的位置。
<div id="block" class="row"></div>
我不确定 JSP 代码希望这对您有用......