1 .必须在页面上传递的json字符串:
var jsonStr='[{'RoomNum':'2',' Person':[{'Id':'1_0',' RoomNo':1,' name ' : ]
[Roomnum':'2',Person': [ { 'Id': '1_0',roomno ' : ' San Zhang ' } ' name '
1 ) .根据json字符串的特征定义对象属性(这里是定义RoomPerson.cs和Person.cs两个类) ) ) ) ) ) ) ) ) )。
publicclassroomperson {//summary//房间总数////summary public int RoomNum { get; set; //summary//客户列表数据///summarypublicilistpersonpersonlist { get; set; }公共类人员{//summary//客户Id (格式: n_m )///summarypublicstringid ) get; set; //summary//客人的房间号////summary public int RoomNo { get; set; //summary//客人的姓名////summarypublicstringname { get; set; (2) .进行转换
listroompersonlist=newtonsoft.JSON.JSON convert.deserializeobjectlistroomperson (JSON str ); 如果json字符串数据不是前面的情况,该如何定义对象类? 让我举另一个例子
1.json字符串数据:
var jsonStr='[{'RowId':1,' template ' : ' hoteltemplateone ',' TemplateId':'1',' check in DTE ' : ] ' template ' : ' hoteltemplatetwo ',' TemplateId':'1',' checkinDTE'3360'2019-05-05}格式:
[Rowid':'1,' template ' : ' hoteltemplateone ',' TemplateId': '1',' check in DTE ' 3360 ' 2019-05 ]
定义RowData.cs类
///summary ///行的数据属性///summarypublicclassrowdata//summary//行的序列号////summary public int RowId { get; set; //summary//模板///summarypublicstringtemplate { get; set; //summary//信息模板id///summarypublicinttemplateid { get; set; //summary//入住日期///summarypublicstringcheckindte { get; set; //summary//结束日期///summarypublicstringcheckoutdte { get; set; }3.转换
ilistrowdatalist=newtonsoft.JSON.JSON convert.deserializeobjectilistrowdata (JSON str ); 摘要:将json字符串转换为对象时,首先查看json字符的格式,然后定义对象类,最后进行转换