记录微信小程序报错 Unexpected end of JSON input;at pages/flow/checkout page getOrderData function

时间:2023-03-09 16:05:24
记录微信小程序报错 Unexpected end of JSON input;at pages/flow/checkout page getOrderData function

微信小程序报错 Unexpected end of JSON input;at pages/flow/checkout page getOrderData function

这个报错是在将数组对象通过页面传值,传到指定页面时报的错。

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

因此解决这个报错的方法是将要传输的数据用 encodeURIComponent()函数(可把字符串作为 URI 组件进行编码) 先进行编码,传输过去后再通过decodeURIComponent()函数解码,最后通过JSON.parse()将其还原为数组对象

记录微信小程序报错 Unexpected end of JSON input;at pages/flow/checkout page getOrderData function

跳转指定页:

记录微信小程序报错 Unexpected end of JSON input;at pages/flow/checkout page getOrderData function

不知道还有没其他的方法,有的话可以分享一下!