原理
将json转成字符串传值JSON.stringify(user);
将字符串转成对象接收 JSON.parse(options.userStr);
传值js
personInfoAction: function(event) {
var user = this.data.user;
//将json转成字符串
let userStr=JSON.stringify(user);
console.log(user);
if(user) {
wx.navigateTo({
url: 'personInfo/index?userStr='+userStr,
success: function(res){
// success
},
})
} else {
wx.navigateTo({
url: 'login/index',
success: function(res){
// success
},
})
}
}
接收js
onLoad: function(options) {
console.log(options);
//将字符串转成json
let user = JSON.parse(options.userStr);
console.log(user);
this.setData({
userListInfo: [ {
title: '头像',
subTitle: '',
icon:'../../../images/icon_img_tx.png',//user.avatar,
hasIcon:true
},{
title: '昵称',
subTitle: user.nickname,
icon:'',
hasIcon:false
}, {
title: '手机号',
subTitle: user.phone,
icon:'',
hasIcon:false
}, {
title: '实名认证',
subTitle: user.truename,
icon:'',
hasIcon:false
}]
});
}
网友评论
console.info(str)
{"id":"002J4UUk29y8BY","name":"薛之谦","avatar":"https://y.gtimg.cn/music/photo_new/T001R300x300M000002J4UUk29y8BY.jpg?max_age=2592000"}
传数据过去后丢失一部分代码
console.log(options)
Object {jsonStr: "{"id":"002J4UUk29y8BY","name":"薛之谦","avatar":"http…usic/photo_new/T001R300x300M000002J4UUk29y8BY.jpg"} //这里数据丢失了,为什么
然后JSON.parse(options.jsonStr)就会报错
SyntaxError: Unexpected end of JSON input
我怎么报这个错