C#字符串怎么转成JSON对象,并解析出里面的数据?

 我来答
momo7572
2018-01-09 · TA获得超过2.4万个赞
知道小有建树答主
回答量:98
采纳率:71%
帮助的人:3.9万
展开全部

构造对象:

public struct ToJsonMy

{

public string result { get; set; }  //属性的名字,必须与json格式字符串中的"key"值一样。

public string res_info { get; set; }

public string queryorder_info { get; set; }   }

转换过程:

public static void JsonMy()

{

string json = Jsonstr("D:\\json\\jsonmy1.txt");//Jsonstr函数读取json数据的文本txt                             

JavaScriptSerializer js = new JavaScriptSerializer();   //实例化一个能够序列化数据的类

ToJsonMy list = js.Deserialize<ToJsonMy>(json);    //将json数据转化为对象类型并赋值给list

string result = list.result;                         

string res_info = list.res_info;

string queryorder_info = list.res_info;

}

json包含对象数组 json数据:jsonmy4.txt

{"result":"0","res_info":"ok","queryorder_info":{"order_num":"5","orderdetail":[{"CFTUin":"769839263","CancelDeadline":"2013-09-12 23:00:00","CheckInDate":"2013-09-12 00:00:00","CheckOutDate":"2013-09-13 00:00:00","CityID":"0101","CurrencyCode":"RMB","HotelID":"00301105","HotelName":"乐家连锁(北京天坛南门店)(原速8酒店(北京天坛南店)",

"ListID":"1000000005201308280002999652","PayAmt":"228","PayType":"0","RommsCnt":"1","SPTransID":"65202157","State":"4"},{"CFTUin":"248486133","CancelDeadline":"2013-10-13 23:00:00","CheckInDate":"2013-10-13 00:00:00","CheckOutDate":"2013-10-18 00:00:00","CityID":"0201","CurrencyCode":"RMB","HotelID":"10201314","HotelName"

"ListID":"1000000005201308280002999413","PayAmt":"1140","PayType":"0","RommsCnt":"1","SPTransID":"65197226","State":"4"}]}}

推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式