普通js通常这样转换
//这是一个json对象
var jsonobj = {"sztno":"330890811","transTime":"2018-5-7 08:00:36","amt":"50"};
//json对象转成json字符串
var jsonstr = JSON.stringify(jsonobj)
console.log("jsonstr=="+jsonstr)
//打印结果:"jsonstr=={"sztno":"330890811","transTime":"2018-5-7 08:00:36","amt":"50"}"
//由json字符串转成json对象
var obj1 = eval('(' + jsonstr + ')');
var obj2 = JSON.parse(jsonstr);
console.log("json obj1=="+JSON.stringify(obj1))
//打印结果:"obj1=={"sztno":"330890811","transTime":"2018-5-7 08:00:36","amt":"50"}"
console.log("json obj2=="+JSON.stringify(obj2))
//打印结果:"obj2=={"sztno":"330890811","transTime":"2018-5-7 08:00:36","amt":"50"}"
微信小程序
//这是一个json对象
var jsonobj = {"sztno":"330890811","transTime":"2018-5-7 08:00:36","amt":"50"};
//json对象转成json字符串(同普通js中相同)
var jsonstr = JSON.stringify(jsonobj)
console.log("jsonstr=="+jsonstr)
//打印结果:"jsonstr=={"sztno":"330890811","transTime":"2018-5-7 08:00:36","amt":"50"}"
//由json字符串转成json对象,eval()函数在小程序用不了,被小程序禁用了
var obj1 = JSON.parse(jsonstr); //可用此方法来转换
console.log("json obj1=="+JSON.stringify(obj1))
//打印结果:"obj1=={"sztno":"330890811","transTime":"2018-5-7 08:00:36","amt":"50"}"
后端
JSONObject nameObject = JSONObject.fromObject(name);
标签:传参,obj1,00,微信,330890811,50,json,jsonstr From: https://blog.51cto.com/u_11343833/6091647