如何將我的JSON字符串轉換爲類C# - 如何JSON字符串轉換爲
這是我的JSON
{ 「的$ id」: 「1」, 「結果」:{ 「$ ID」: 「2」, 「日期時間」:23821964, 「列表」:[{ 「$ ID」: 「3」, 「用戶ID」:302, 「UID」: 「302_UID」, 「Title」:「شیدکو」, 「Sender」:「شیدکو」, 「Answer」:「」, 「註釋」: 「測試2」, 「ProductTitle」:空, 「CommentId」:77, 「標識」: 「http://www.domain.com/Commercial/User/302/Logo/tmpF0BF.jpg」, 「日期」:24302057, 「AnswerDate」:-2123661683, 「 AnswerEdit「:假, 」CommentEdit「:假, 」ForfeitCount「:0, 」RewardCount「:0, 」ThisCountReport「:2, 」報道「:[{ 」$ ID「: 」4「, 「BlockerId」:355, 「Title」:「محتوایغیراخلاقی」, 「Date」:-19527396, 「ForfeitCount」:0, 「RewardCount」:0 },{ 「的$ id」: 「5」, 「BlockerId」:355, 「標題」: 「محتوایغیرمرتبط」, 「日期」:-19527382, 「ForfeitCount」 :0, 「RewardCount」:0 }], 「寶石」:0 },{ 「$ ID」: 「6」, 「用戶ID」:302, 「UID」: 「302_UID」, 「Title」:「شیدکو」, 「Sender」:「شیدکو」, 「Answer」:「」, 「Comment」:「test 2」, 「ProductTitle」:null, 「CommentId」:77, 「標誌」: 「http://www.www.domain.com/Commercial/User/302/Logo/tmpF0BF.jpg」, 「日期」:24302057, 「AnswerDate」:-2123661683, 「AnswerEdit」:假的, 「CommentEdit」:假
}]
},
"StatusCode": "Created",
"Description": null
}
我做這些步驟,但沒有任何反應
JObject json1 = JObject.Parse(strMyJson);
_CommentAdmindto flight = Newtonsoft.Json.JsonConvert.DeserializeObject<_CommentAdmindto>(json1.ToString());
_CommentAdmindto deserializedProduct = JsonConvert.DeserializeObject<_CommentAdmindto>(json);
_CommentAdmindto deserializedProduct1 = ConvertJsonToClass<_CommentAdmindto>(strMyJson);
JsonSerializer serializer = new JsonSerializer();
_CommentAdmindto p = (_CommentAdmindto)serializer.Deserialize(new JTokenReader(strMyJson), typeof(_CommentAdmindto));
這裏是我的類和函數:
public static T ConvertJsonToClass<T>(string json)
{
System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
return serializer.Deserialize<T>(json);
}
}
public class _CommentAdmindto
{
public long dateTime { get; set; }
public IQueryable<CommentDtoAdmin> list { get; set; }
}
public class CommentDtoAdmin
{
public long UserId { get; set; }
public string UID { get; set; }
public string Title { get; set; }
public string Sender { get; set; }
public string Answer { get; set; }
public string Comment { get; set; }
public string ProductTitle { get; set; }
public long CommentId { get; set; }
public string Logo { get; set; }
public long Date { get; set; }
public long AnswerDate { get; set; }
public bool AnswerEdit { get; set; }
public bool CommentEdit { get; set; }
}
我想它是一個重複的問題http://stackoverflow.com/questions/4718888/how-to-convert-json-to-c-sharp-classes –
@HussainPatel在你的鏈接,他們沒有把它添加到類,請看看它吧 – Dav
你的JSON與你的模型不匹配 –