Unexpected token in JSON at position 0
来源:互联网 发布:碣石鱼刺车行淘宝 编辑:程序博客网 时间:2024/06/06 01:17
最近的一个android项目碰到一个问题,解析web返回的一个json串,出现
Unexpected token in JSON at position 0
这样的错误,日志打印,字符串本身看上去没有任何问题,只是把字符串放到文本编辑器里,然后按键盘移动光标,发现字符串的第一个字符‘{’之前,确实有一个字符,但是肉眼看不见,这就非常神奇了
于是乎考虑这个字符是特殊字符,那么首先把这个字符拷贝出来,解析成ascii码试试
然后惊奇的发现,这个字符换算成十六进制是0xfeff
找了一圈,发现了这个 http://www.169it.com/article/11324591921744705430.html
问题看上去是找到了,那么处理方式也就出来了
对每次接收到的响应字符串做一个特殊处理,判断下第一个字符,如果是非正常ascii码的,直接去除即可
typescript代码大概长这样:
let firstCode = resp.charCodeAt(0);console.log('response 0:' + firstCode);if (firstCode < 0x20 || firstCode > 0x7f) {console.log('response get sp char');resp = resp.substring(1); // 去除第一个字符console.log('response:' + resp);}
阅读全文
0 0
- Uncaught SyntaxError: Unexpected token < in JSON at position 0
- 解决方法 Uncaught SyntaxError: Unexpected token < in JSON at position 0
- Unexpected token in JSON at position 0
- SyntaxError: Unexpected token s in JSON at position 111518
- SyntaxError: Unexpected token s in JSON at position 1
- Uncaught SyntaxError: Unexpected token ] in JSON at position 问题
- 【Angular2】Unexpected token / in JSON at position 35
- Uncaught SyntaxError: Unexpected token o in JSON at position 1
- Uncaught SyntaxError: Unexpected token o in JSON at position 1
- Uncaught SyntaxError: Unexpected token o in JSON at position 1
- Atitit Uncaught (in promise) SyntaxError Unexpected token < in JSON at position 0
- primefaces 推送服务报Uncaught SyntaxError: Unexpected token < in JSON at position 0
- 【已解决】Uncaught SyntaxError: Unexpected token in JSON at position 0
- Unexpected token u in JSON at position 0 的解决过程
- JSON.parse(str)报错Unexpected token t in JSON at position 1
- JSON.parse() Unexpected token i in JSON at position 2 报错问题
- JSON.parse()报错 Unexpected token i in JSON at position 2
- ajax post请求发送json数据报错unexpected token in json at position的问题解决
- linux下杀死进程(kill)的N种方法
- Jquery
- Eclipse中添加web dynamic project
- 管家婆创业版 v3.5.1.13 官方版
- 无限轮播.简洁版Banner
- Unexpected token in JSON at position 0
- bzoj1051 [HAOI2006]受欢迎的牛(tarjan求强连通分量)
- Android网络数据解析之Jsoup
- head dump分析
- 随便写写传传吧
- 购物车全选
- 提高程序员生产力的代码生成器
- java基础
- Sublime3新版激活码 2017/9/14亲测可用