微信小程序 Unexpected end of JSON input/Unexpected token o in JSON at position 1

版权声明:本文为博主原创文章,如需转载请务必注明原地址。 https://blog.csdn.net/qq_31393401/article/details/81412972

原因

JSON.parse无法识别某些url中的特殊字符,所以报错

解决方案

对需要做JSON.parse的字符串先做编码处理,encodeURIComponent(str),再用JSON.parse将其转成js对象,最后通过decodeURIComponent(str)将字符串解码即可使用。

猜你喜欢

转载自blog.csdn.net/qq_31393401/article/details/81412972
今日推荐