Error in created hook: “SyntaxError: Unexpected token u in JSON at position 0

Problem: an error occurs when the page receives the passed JSON object

Reference page:

let invite = {
				id:albumID,
				unionid,
				role
			}
wx.navigateTo({
		url: `/pages/web/web?id=${id}&isShared=1&invite=${JSON.stringify(invite)}`,
	});

Receive page printing parameters:

console.log('invite',this.invite);
//console.log('invite',JSON.parse(this.invite));//报错 SyntaxError: Unexpected token u in JSON at position 0

The result is

Solution:

When receiving JSON data, decodeuri () is used for decoding

let {id,role,unionid} = JSON.parse(decodeURI(this.invite));


Read More: