Forum General

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

How can i deserialize the json

Ajay87Ajay87 INMember ✭✭✭
edited May 2020 in General

I have not been able to deserialize this json from response, plz help
{"diagnostics":{"errorCode":5,"status":"success","message":"Data Successfully Inserted","warnings":null,"processingTime":0},"data":null}

i am using this
var resultString = await response.Content?.ReadAsStringAsync();
var responseMessage = JsonConvert.DeserializeObject(resultString);

Thanks

Best Answer

  • JohnHJohnH GBMember ✭✭✭✭✭
    Accepted Answer

    Have you created your DTO class to match your JSON? There are websites that will do that for you if you aren't sure.
    Then, you can use JSON.NET to deserialise into an instance of that class.

Answers

  • JohnHJohnH GBMember ✭✭✭✭✭
    Accepted Answer

    Have you created your DTO class to match your JSON? There are websites that will do that for you if you aren't sure.
    Then, you can use JSON.NET to deserialise into an instance of that class.

  • AndreaRicciardiAndreaRicciardi USMember

    Hi Ajay87,
    be sure that you've imported Newtonsoft.Json in your solution
    Cheers

  • soufianemarlysoufianemarly Member ✭✭✭

    add this line after your code
    JObject s = JObject.Parse(responseMessage);
    Console.WriteLine("Json result "+s);

Sign In or Register to comment.