Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to deserialize specific Json

Hi guys i try to deserialize a json but this result null , posible its so simple but i cant resolve now , i try this forms, and i use Newtonsoft

if (response.Content.Contains("error"))
{
    JObject jObject = JObject.Parse(response.Content);
    dynamic x = JsonConvert.DeserializeObject<Error>(response.Content);
    error = JsonConvert.DeserializeObject<Error>(response.Content);
    JArray recibos = (JArray)jObject["error"];
    return error;
}

this its the json my response.content

"{\"error\":{\"code\":-10,\"message\":{\"lang\":\"en-us\",\"value\":\"The warehouse is not defined for the item.  [OWOR.Warehouse]\"}}}"

and my class

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

public class Error
{
    public int code { get; set; }
    public Message message { get; set; }

    public class Message
    {
        public string lang { get; set; }
        public string value { get; set; }
    }
}

>Solution :

try this


if (response.Content != null)
{            {
Data    data = JsonConvert.DeserializeObject<Data>(response.Content);
}

and add class Data (you can change name)

public class Data
{
    public  Error error {get; set;}
}

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading