.NET MVC 序列化与反序列化
using System.Runtime.Serialization.Json;
using System.IO;
using System.Text;
//序列化
public string MySerialize(object o)
{
//序列化
DataContractJsonSerializer json = new DataContractJsonSerializer(o.GetType());
using (MemoryStream stream = new MemoryStream())
{
json.WriteObject(stream, o);
string JsonData = Encoding.UTF8.GetString(stream.ToArray());
return JsonData;
}
}
$.ajax({
type: "GET",
url: "../product/GetProductList",
data: {active:1},
dataType: "json",
success: function (data) {
ProductList=data;
var html = '';
if (data != "") {
for (var i = 0; i < data.length; i++) {
html += "<tr>";
html += '<td style="font-size:18px;"><a onclick="ShowProductDetails('+data[i].FoodID+')">'+data[i].FoodName+'</a></td>'
html += "<td>约 " + data[i].Specifications + "</td>"
html += "<td style='text-align:center'>" + data[i].Price + "</td>"
html += '<td><label class="checkbox-inline"><input id="'+data[i].FoodID+'" type="checkbox" onclick="CheckboxClick('+data[i].FoodID+')" value="" style="zoom:300%; float:right;margin-top:-1px;margin-left:-6px;"></label></td>'
html += "</tr>";
}
$("#ProductList").empty();
$("#ProductList").html(html);
}
}
});
using System.IO;
using System.Web.Script.Serialization;
//反序列化
public List<T> MyDeserialize<T>(HttpRequestBase request)
{
var sr = new StreamReader(Request.InputStream);
var stream = sr.ReadToEnd();
//反序列化
JavaScriptSerializer js = new JavaScriptSerializer();
var List = js.Deserialize<List<T>>(stream);
return List;
}
$.ajax({
type: "POST",
url: "../order/Pay",
data:JSON.stringify(Orders),
dataType: "json",
success: function (data) {
if (data != "") {
if(data.Code==200)
{
if(hb)
{
window.location.href = '../order/status?NO='+data.NO;
}
else
{
window.location.href = '../order/status?hb=false&NO='+data.NO;
}
}
}
},
error: function () {
alert("网络异常,请稍后再试···");
}
});
最新文章
- node.js如何处理请求的路由
- proteus 运行出错,用户名不可使用中文!
- 快速搭建Redis缓存数据库
- jQuery -&;gt; 获取各种滤芯(filter)
- Windows 下安装 Oracle 12c 教程
- DDS视图&;Button控件
- Cocos2d中update与fixedUpdate的区别(三)
- POJ1006: 中国剩余定理的完美演绎
- redis的LRU算法(一)
- spring boot监控--actuator
- Sqlserver 命令行方式修改 用户密码的方法
- 2018即将过去,立个flag
- cocos2d-x JS 利用重复动作实现动画播放(实现倒计时)
- Python高阶函数_map/reduce/filter函数
- VS2015 C#的单元测试
- 【LOJ】#2230. 「BJOI2014」大融合
- Pandas常用命令
- git 代码冲突处理
- November 27th 2016 Week 48th Sunday
- (C++)UrlEncode的标准实现
热门文章
- (导航页)OpenStack-M版-双节点手工搭建-附B站视频
- static inline和inline的区别——stm32实测
- R-FCN:
- C++中整型变量的存储大小和范围
- 支持TV远程控制的WIN10PEX64_17763网络版by双心
- vue_02day练习
- Python3.6 SyntaxError: &#39;ascii&#39; codec can&#39;t decode byte 0xe5 in position 7: ordinal not in range(128)
- SpringBootThymeleaf案例
- C语言I作业12—学期总结
- 热情组——项目冲刺 Day5