关于json数据传输乱码问题


关于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对象带回去,结果为:

  1. 0:{data: "16日(周一)", tem: "19℃/15℃", wea: "阴转多云", win: "东北风 3-4级"}
  2. 1:{data: "16日(周一)", tem: "19℃/15℃", wea: "阴转多云", win: "东北风 3-4级"}
  3. 2:{data: "16日(周一)", tem: "19℃/15℃", wea: "阴转多云", win: "东北风 3-4级"}
  4. 3:{data: "16日(周一)", tem: "19℃/15℃", wea: "阴转多云", win: "东北风 3-4级"}
  5. 4:{data: "16日(周一)", tem: "19℃/15℃", wea: "阴转多云", win: "东北风 3-4级"}
  6. 5:{data: "16日(周一)", tem: "19℃/15℃", wea: "阴转多云", win: "东北风 3-4级"}
  7. 6:{data: "16日(周一)", tem: "19℃/15℃", wea: "阴转多云", win: "东北风 3-4级"}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不染心

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值