(1)同(2)public JsonResult JsonUserGet() {
DataSet ds = Web_User.P_LG_User_Get(nUserId);
return Json(JsonUtils.ToJsonArray(ds));内部使用jsonSerializer进行序列化。
}
(2).Net:json序列化:JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
return jsonSerializer.Serialize(rst);
(3)javascript序列化
j1)avascript中json对象、json数组、json字符串互转及取值
json类型的字符串转换为json对象及取值
var jsonString = '{"bar":"property","barr":10}';
var jsObject = JSON.parse(jsonString); //转换为json对象
console.log(jsObject.bar); //取json中的值 property
2)
json对象转为json类型的字符串
var jsonString = '{"bar":"property","barr":10}';
var jsObject = JSON.parse(jsonString); //转换为json对象
var str = JSON.stringify(jsObject); //转换为json类型的字符串
3)
json数组类型的字符串转换为json及取值 和json对象转换为转换为json字符串
//json数组类型字符串取值
var jsonStr = '[{"id":"01","open":false,"pId":"0","name":"A部门"},{"id":"01","open":false,"pId":"0","name":"A部门"},{"id":"011","open":false,"pId":"01","name":"A部门"},{"id":"03","open":false,"pId":"0","name":"A部门"},{"id":"04","open":false,"pId":"0","name":"A部门"}, {"id":"05","open":false,"pId":"0","name":"A部门"}, {"id":"06","open":false,"pId":"0","name":"A部门"}]';
var jsonObj = JSON.parse(jsonStr);//转换为json对象
for(var i=0;i<jsonObj.length;i++){
console.log(jsonObj[i].id); //取json中的值
}
console.log(jsonObj)
var jsonStr1 = JSON.stringify(jsonObj)
console.log(jsonStr1+"jsonStr1")
4)
//获取交易记录
var dt = ViewBag.ListJson != null ? (ViewBag.ListJson as System.Data.DataSet).Tables[0] : new System.Data.DataTable();