5***@qq.com
5***@qq.com
  • 发布:2019-02-16 15:24
  • 更新:2020-11-30 14:23
  • 阅读:15880

uni-app json 解析

分类:uni-app

大佬们 如果api返回数据{"data":"{"type":"ping"}"}是这种格式,安卓json.parse能解析,ios却报错
15:19:10.003 [ERROR] : thirdScriptError
15:19:10.003 JSON Parse error: Expected '}';at pages/index/index onShow function;at onSocketMessage callback function
15:19:10.003 parse@[native code]
15:19:10.003 __uniappservice.html:1:202400
15:19:10.004 __uniappservice.html:1:482542
15:19:10.004 __uniappservice.html:1:258607
15:19:10.004 __uniappservice.html:1:485949
15:19:10.004 __uniappservice.html:1:236065
15:19:10.004 l8g@__uniappservice.html:1:96410
15:19:10.004 e6@__uniappservice.html:1:2449
15:19:10.004 k0@__uniappservice.html:1:84002
15:19:10.004 __uniappservice.html:1:84374
怎么解决哦

2019-02-16 15:24 负责人:无 分享
已邀请:
5***@qq.com

5***@qq.com (作者)

具体数据格式有
{"data":"{"type":"welcome","id":7f0000010a8e000005c7}"}


{"data":"{"type":"tip","message":"\u5df2\u6536\u5230\u4f60\u7684\u4fe1\u606f","id":1550304650}"}

{"data":"{"type":"closed","id":1550304632}"}

{"data":"{"type":"ping"}"}

5***@qq.com

5***@qq.com (作者)

{"data":"{"type":"welcome","id":7f0000010a8e000005c7}"} 好像是这一串有问题 7f0000010a8e000005c7

含光

含光

我这直接将一个对象json.stringify后再json.parse都报错,怎么情况呢?提示信息是:‘SyntaxError: Unexpected token � in JSON at position 0’

  • 5***@qq.com (作者)

    一般格式正确是没有问题的


    2020-12-04 17:12

沐尘

沐尘 - 心有期许,未来无惧。向美而生,向上而行

可以试试eval('(' + res.data + ')');//转json

该问题目前已经被锁定, 无法添加新回复