php json输出后 u6563,String转Json,数据格式没问题,始终报String cannot be converted to JSONObject的解决办法...

服务器端返回的数据如下:

{"status":1,"msg":"","data":{"companyname":"","resCount":4,"res":[{"id":"120","sp":"\u56db\u5ddd\u7701","sc":"\u6210\u90fd\u5e02","ep":"\u5c71\u897f\u7701","ec":"\u592a\u539f\u5e02","product_type":"\u666e\u8d27","pack_type":"\u7bb1\u88c5","product_weight":"4.0","product_volume":"23.0","deadline":"4\u5929\u540e\u8fc7\u671f","distance":"\u8ddd\u79bb10.0\u516c\u91cc"},{"id":"119","sp":"\u56db\u5ddd\u7701","sc":"\u6210\u90fd\u5e02","ep":"\u5317\u4eac","ec":"\u5317\u4eac\u5e02","product_type":"\u666e\u8d27","pack_type":"\u7bb1\u88c5","product_weight":"21.0","product_volume":"21.0","deadline":"4\u5929\u540e\u8fc7\u671f","distance":"\u8ddd\u79bb11.4\u516c\u91cc"},{"id":"115","sp":"\u56db\u5ddd\u7701","sc":"\u6210\u90fd\u5e02","ep":"\u4e0a\u6d77","ec":"\u4e0a\u6d77\u5e02","product_type":"\u666e\u8d27","pack_type":"\u6563\u4ef6","product_weight":"3.0","product_volume":"30.0","deadline":"53\u5929\u540e\u8fc7\u671f","distance":"\u8ddd\u79bb20.8\u516c\u91cc"},{"id":"110","sp":"\u56db\u5ddd\u7701","sc":"\u6210\u90fd\u5e02","ep":"\u798f\u5efa\u7701","ec":"\u53a6\u95e8\u5e02","product_type":"\u666e\u8d27","pack_type":"\u7bb1\u88c5","product_weight":"13.0","product_volume":"12.0","deadline":"50\u5929\u540e\u8fc7\u671f","distance":"\u8ddd\u79bb28.0\u516c\u91cc"}],"page":1}}

绝对是一个正确的JSONObject格式,但 new JSONObject(res)的时候总是报Value of type java.lang.String cannot be converted to JSONObject。后来发现是UTF-8的BOM头问题,加上以下代码后正常:

if(res.startsWith("\ufeff")){

res = res.substring(1);

}在确认JSON数据格式没有问题的前提下,100%是因为UTF-8的BOM头。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值