一个eventInfo对象下面有多个presentation对象
将下面的jason串转换成 eventInfo和presentation对象
{
"eventInfo": [
{
"eiId": 1,
"eiEventName": "test_event_1",
"eiEventTypeId": 5,
"eiCreaterId": 1,
"eiStartTime": "2014-06-19 10:30:00.0",
"eiEndTime": "2014-06-19 11:30:00.0",
"eiCreateDate": "2014-06-10 10:28:38.0",
"eiUpdateDate": "2014-06-24 11:09:59.0",
"eiDeleteFlg": 0,
"presentation": [
{
"pExtractPointFlg": 0,
"piCreateDate": "2014-06-16 14:00:45.0",
"piCreaterId": 1,
"piDeleteFlg": 0,
"piEndTime": "2014-06-17 10:28:27.0",
"piEventId": 1,
"piExtractNewFlg": 0,
"piId": "304d3bf393234734b252a6e6a20b62bd",
"piLanguage": 1,
"piPptName": "dddd",
"piPresentationName": "111111111",
"piPresentorMail": "wuxu@test.com",
"piPresentorName": "wuxu_DDDD",
"piShareFlag": 0,
"piSharePDFName": "",
"piStartTime": "2014-06-17 10:28:27.0",
"piStatus": 0,
"piUpdateDate": "2014-06-16 14:00:45.0"
},
{
"pExtractPointFlg": 0,
"piCreateDate": "2014-06-16 09:52:52.0",
"piCreaterId": 1,
"piDeleteFlg": 0,
"piEndTime": "2014-06-17 10:28:27.0",
"piEventId": 1,
"piExtractNewFlg": 0,
"piId": "40c5592085194aa488c3e2aede028ea3",
"piLanguage": 1,
"piPptName": "dddd",
"piPresentationName": "333333333",
"piPresentorMail": "wuxu@test.com",
"piPresentorName": "wuxu_DDDD",
"piShareFlag": 0,
"piSharePDFName": "",
"piStartTime": "2014-06-17 10:28:27.0",
"piStatus": 0,
"piUpdateDate": "2014-06-16 13:21:19.0"
},
{
"pExtractPointFlg": 0,
"piCreateDate": "2014-06-16 14:00:47.0",
"piCreaterId": 1,
"piDeleteFlg": 0,
"piEndTime": "2014-06-17 10:28:27.0",
"piEventId": 1,
"piExtractNewFlg": 0,
"piId": "818736085d7840b1a16425e181f44d6c",
"piLanguage": 1,
"piPptName": "dddd",
"piPresentationName": "444444444",
"piPresentorMail": "wuxu@test.com",
"piPresentorName": "wuxu_DDDD",
"piShareFlag": 0,
"piSharePDFName": "",
"piStartTime": "2014-06-17 10:28:27.0",
"piStatus": 0,
"piUpdateDate": "2014-06-16 14:00:47.0"
},
{
"pExtractPointFlg": 0,
"piCreateDate": "2014-06-16 14:00:45.0",
"piCreaterId": 1,
"piDeleteFlg": 0,
"piEndTime": "2014-06-17 10:28:27.0",
"piEventId": 1,
"piExtractNewFlg": 0,
"piId": "d57a7e5eb1b84e87a3ee179523db1560",
"piLanguage": 1,
"piPptName": "dddd",
"piPresentationName": "666666666",
"piPresentorMail": "wuxu@test.com",
"piPresentorName": "wuxu_DDDD",
"piShareFlag": 0,
"piSharePDFName": "",
"piStartTime": "2014-06-17 10:28:27.0",
"piStatus": 0,
"piUpdateDate": "2014-06-16 14:00:45.0"
},
{
"pExtractPointFlg": 0,
"piCreateDate": "2014-06-16 14:00:43.0",
"piCreaterId": 1,
"piDeleteFlg": 0,
"piEndTime": "2014-06-17 10:28:27.0",
"piEventId": 1,
"piExtractNewFlg": 0,
"piId": "fc96d0e48eb342b089dde47116744533",
"piLanguage": 1,
"piPptName": "dddd",
"piPresentationName": "999999999",
"piPresentorMail": "wuxu@test.com",
"piPresentorName": "wuxu_DDDD",
"piShareFlag": 0,
"piSharePDFName": "",
"piStartTime": "2014-06-17 10:28:27.0",
"piStatus": 0,
"piUpdateDate": "2014-06-16 14:00:43.0"
}
]
},
{
"eiId": 2,
"eiEventName": "test_event_2",
"eiEventTypeId": 1,
"eiCreaterId": 2,
"eiStartTime": "2014-06-17 10:28:27.0",
"eiEndTime": "2014-06-17 10:28:27.0",
"eiCreateDate": "2014-06-10 15:09:13.0",
"eiUpdateDate": "2014-06-16 13:21:41.0",
"eiDeleteFlg": 0,
"presentation": [
{
"pExtractPointFlg": 0,
"piCreateDate": "2014-06-16 14:00:46.0",
"piCreaterId": 1,
"piDeleteFlg": 0,
"piEndTime": "2014-06-17 10:28:27.0",
"piEventId": 2,
"piExtractNewFlg": 0,
"piId": "3a587d14d8de419c8f63ce2e9fcfc20f",
"piLanguage": 1,
"piPptName": "dddd",
"piPresentationName": "222222222",
"piPresentorMail": "wuxu@test.com",
"piPresentorName": "wuxu_DDDD",
"piShareFlag": 0,
"piSharePDFName": "",
"piStartTime": "2014-06-17 10:28:27.0",
"piStatus": 0,
"piUpdateDate": "2014-06-16 14:00:46.0"
},
{
"pExtractPointFlg": 0,
"piCreateDate": "2014-06-16 14:00:46.0",
"piCreaterId": 1,
"piDeleteFlg": 0,
"piEndTime": "2014-06-17 10:28:27.0",
"piEventId": 2,
"piExtractNewFlg": 0,
"piId": "c90a18391acb4f53b55ff176d0041c81",
"piLanguage": 1,
"piPptName": "dddd",
"piPresentationName": "555555555",
"piPresentorMail": "wuxu@test.com",
"piPresentorName": "wuxu_DDDD",
"piShareFlag": 0,
"piSharePDFName": "",
"piStartTime": "2014-06-17 10:28:27.0",
"piStatus": 0,
"piUpdateDate": "2014-06-16 14:00:46.0"
},
{
"pExtractPointFlg": 0,
"piCreateDate": "2014-06-16 09:41:18.0",
"piCreaterId": 1,
"piDeleteFlg": 0,
"piEndTime": "2014-06-17 10:28:27.0",
"piEventId": 2,
"piExtractNewFlg": 0,
"piId": "f11de1ab83854f7192facabd45f90ba8",
"piLanguage": 1,
"piPptName": "dddd",
"piPresentationName": "777777777",
"piPresentorMail": "wuxu@test.com",
"piPresentorName": "wuxu_DDDD",
"piShareFlag": 0,
"piSharePDFName": "",
"piStartTime": "2014-06-17 10:28:27.0",
"piStatus": 0,
"piUpdateDate": "2014-06-16 09:41:18.0"
},
{
"pExtractPointFlg": 0,
"piCreateDate": "2014-06-16 14:00:44.0",
"piCreaterId": 1,
"piDeleteFlg": 0,
"piEndTime": "2014-06-17 10:28:27.0",
"piEventId": 2,
"piExtractNewFlg": 0,
"piId": "f884e105bbf641e3a6a0686d4fafe439",
"piLanguage": 1,
"piPptName": "dddd",
"piPresentationName": "888888888",
"piPresentorMail": "wuxu@test.com",
"piPresentorName": "wuxu_DDDD",
"piShareFlag": 0,
"piSharePDFName": "",
"piStartTime": "2014-06-17 10:28:27.0",
"piStatus": 0,
"piUpdateDate": "2014-06-16 14:00:44.0"
}
]
}
]
}
1.首先创建这样的一个 类:EventInfo类中包含泛型集合为Presentation 的 属性
2.再使用相关的工具反序列化出来。Newtonsoft.Json.JavaScriptConvert.DeserializeObject<EventInfo>('{...}');
( Newtonsoft.Json.dll工具,网上可以download)
找不到 这 个 JavaScriptConvert 类 / 命名空间啊
这是我的笨方法
JObject b = JObject.Parse(strResult); string strEvent = b.SelectToken("eventInfo").ToString(); JArray jEventArr = JArray.Parse(strEvent); List<EventInfoModel> listEvent = new List<EventInfoModel>(); foreach (JObject jEventObj in jEventArr) { EventInfoModel eventInfo = new EventInfoModel() { CreateDate = Convert.ToDateTime(jEventObj["eiCreateDate"].ToString()), CreaterId = jEventObj["eiCreaterId"].ToString(), DeleteFlag = jEventObj["eiDeleteFlg"].ToString(), EndTime = Convert.ToDateTime(jEventObj["eiEndTime"].ToString()), EventId = jEventObj["eiId"].ToString(), EventName = jEventObj["eiEventName"].ToString(), EventTypeId = jEventObj["eiEventTypeId"].ToString(), PreCollection = new ObservableCollection<PresentationModel>(), StartTime = Convert.ToDateTime(jEventObj["eiStartTime"].ToString()), UpdateDate = Convert.ToDateTime(jEventObj["eiUpdateDate"].ToString()) }; listEvent.Add(eventInfo); string strPre = jEventObj.SelectToken("presentation").ToString(); JArray jPreArr = JArray.Parse(strPre); foreach (JObject jPreObj in jPreArr) { PresentationModel presentation = new PresentationModel(); presentation.CreateDate = Convert.ToDateTime(jPreObj["piCreateDate"].ToString()); presentation.CreaterId = jPreObj["piCreaterId"].ToString(); presentation.DeleteFlag = jPreObj["piDeleteFlg"].ToString(); presentation.EndTime = Convert.ToDateTime(jPreObj["piEndTime"].ToString()); presentation.EventId = jPreObj["piEventId"].ToString(); presentation.ExtractNewFlag = jPreObj["piExtractNewFlg"].ToString(); presentation.ExtractPointFlag = jPreObj["pExtractPointFlg"].ToString(); presentation.Language = jPreObj["piLanguage"].ToString(); presentation.PptName = jPreObj["piPptName"].ToString(); presentation.PreId = jPreObj["piId"].ToString(); presentation.PresentationName = jPreObj["piPresentationName"].ToString(); presentation.PresentatorMail = jPreObj["piPresentorMail"].ToString(); presentation.PresentatorName = jPreObj["piPresentorName"].ToString(); presentation.ShareFlag = jPreObj["piShareFlag"].ToString(); presentation.SharePdfName = jPreObj["piSharePDFName"].ToString(); presentation.StartTime = Convert.ToDateTime(jPreObj["piStartTime"].ToString()); presentation.Status = jPreObj["piStatus"].ToString(); presentation.UpdateDate = Convert.ToDateTime(jPreObj["piUpdateDate"].ToString()); eventInfo.PreCollection.Add(presentation); } }