您的位置:首页 > Web前端 > JavaScript

Asp.net C# 使用Newtonsoft.Json 进行通信

2011-06-09 12:47 295 查看
Asp.netC#使用Newtonsoft.Json进行通信
2010/03/2011:26
1.将DataTable序列化成JSON

usingNewtonsoft.Json;
usingNewtonsoft.Json.Converters;

stringJson=JsonConvert.SerializeObject(GetData(filename),newDataTableConverter());//将datatable转成Json格式返回

2.反序列化JSON


usingNewtonsoft.Json;
usingNewtonsoft.Json.Converters;
usingNewtonsoft.Json.Linq;
//usingSystem.Net.Json;

JObjecto=JObject.Parse(@"{

""Stores"":[

""LambtonQuay"",

""WillisStreet""

],

""Manufacturers"":[

{

""Name"":""AcmeCo"",

""Products"":[

{

""Name"":""Anvil"",

""Price"":50

}

]

},

{

""Name"":""Contoso"",

""Products"":[

{

""Name"":""ElbowGrease"",

""Price"":99.95

},

{

""Name"":""HeadlightFluid"",

""Price"":4

}

]

}

]

}");


stringname=(string)o.SelectToken("Manufacturers[0].Name");

//AcmeCo


decimalproductPrice=(decimal)o.SelectToken("Manufacturers[0].Products[0].Price");

//50


stringproductName=(string)o.SelectToken("Manufacturers[1].Products[0].Name");

//ElbowGrease


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: