Wie kann ich meine Json-Zeichenfolge Klasse konvertierenC# - Wie json String-Klasse umwandeln
das ist mein json
{ "$ id": "1", "Ergebnis": { "$ id": "2", "Datetime": 23.821.964, "list": [{ "$ id": "3", "UserId": 302, "UID": "302_UID", "Titel": "شیشیکک", "Absender": "شیشیکک", "Antwort": "", "Kommentar": "Test 2", "ProductTitle": null, "CommentId": 77, "Logo": "http://www.domain.com/Commercial/User/302/Logo/tmpF0BF.jpg", "Datum": 24.302.057, "AnswerDate": -2123661683, " AnswerEdit ": false, "CommentEdit": false, "ForfeitCount": 0, "RewardCount": 0, "ThisCountReport": 2, "Berichtet": [{ "$ id": "4" ist, "BlockerId": 355, "Titel": "محتوای غیر اخلایی", "Datum": -19527396, "ForfeitCount": 0, "RewardCount": 0 }, { "$ id": "5", "BlockerId": 355, "Titel": "محتوای غیر مرتبط", "Datum": -19527382, "ForfeitCount" : 0, "RewardCount": 0 }], "Gem": 0 }, { "$ id": "6", "UserId": 302, "UID": "302_UID", "Titel": "شیشیکک", "Absender": "شیشیکک", "Antwort": "", "Kommentar": "Test 2", "ProductTitle": null, "CommentId": 77, "Logo": "http://www.www.domain.com/Commercial/User/302/Logo/tmpF0BF.jpg", "Datum": 24.302.057, "AnswerDate": -2123661683, "AnswerEdit": false, "CommentEdit": false
}]
},
"StatusCode": "Created",
"Description": null
}
und ich diesen Schritt, aber es passiert nichts
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));
und hier ist meine Klasse und Funktion:
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; }
}
Ich nehme an, es ist eine doppelte Frage http://Stackoverflow.com/questions/4718888/how-to-convert-json-to-c-sharp-classes –
@HussainPatel auf Ihrem Link, sie haben es nicht hinzugefügt Klasse, einen Blick auf sie haben, bitte – Dav
Ihre json nicht mit Ihrem Modell –