关于json数据传输乱码问题
ArrayList<weather> lists=new ArrayList<weather>();
JSONArray jsonArray=JSONArray.fromObject(lists);
String result=jsonArray.toString();
writer.write("("+result+")");
在数据传输的,或者将result打印出来以后出现乱码的现象,结果是:
[{"data":"16\u65e5\uff08\u5468\u4e00\uff09","tem":"19\u2103/15\u2103","wea":"\u9634\u8f6c\u591a\u4e91","win":"\u4e1c\u5317\u98ce\u00203\u002d4\u7ea7"},{"data":"16\u65e5\uff08\u5468\u4e00\uff09","tem":"19\u2103/15\u2103","wea":"\u9634\u8f6c\u591a\u4e91","win":"\u4e1c\u5317\u98ce\u00203\u002d4\u7ea7"},{"data":"16\u65e5\uff08\u5468\u4e00\uff09","tem":"19\u2103/15\u2103","wea":"\u9634\u8f6c\u591a\u4e91","win":"\u4e1c\u5317\u98ce\u00203\u002d4\u7ea7"},{"data":"16\u65e5\uff08\u5468\u4e00\uff09","tem":"19\u2103/15\u2103","wea":"\u9634\u8f6c\u591a\u4e91","win":"\u4e1c\u5317\u98ce\u00203\u002d4\u7ea7"},{"data":"16\u65e5\uff08\u5468\u4e00\uff09","tem":"19\u2103/15\u2103","wea":"\u9634\u8f6c\u591a\u4e91","win":"\u4e1c\u5317\u98ce\u00203\u002d4\u7ea7"},{"data":"16\u65e5\uff08\u5468\u4e00\uff09","tem":"19\u2103/15\u2103","wea":"\u9634\u8f6c\u591a\u4e91","win":"\u4e1c\u5317\u98ce\u00203\u002d4\u7ea7"},{"data":"16\u65e5\uff08\u5468\u4e00\uff09","tem":"19\u2103/15\u2103","wea":"\u9634\u8f6c\u591a\u4e91","win":"\u4e1c\u5317\u98ce\u00203\u002d4\u7ea7"}]
可能是json数据格式问题,
我是这样接解决的:在前端设置一个回调函数,
String jsonp=request.getParameter("callbackparam");
JSONArray jsonArray=JSONArray.fromObject(lists);
String result=jsonArray.toString();
writer.write(jsonp+"("+result+")");
然后通过回调函数将json对象带回去,结果为: