1

I have got following JSON that should be deserialized to C# class:

{"status":"error","messages":[{"level":"error","key":"InvalidTokenError","dsc":"Invalid token"}]}

So I have a questions what is the kind of type should be

[{"level":"error","key":"InvalidTokenError","dsc":"Invalid token"}]

?

Is this array, list or class?

2 Answers 2

2

You can use json2csharp.com to get the types of the JSON.

JSON:

{"status":"error","messages":[{"level":"error","key":"InvalidTokenError","dsc":"Invalid token"}]}

Here is the classes generated for your JSON:

public class Message
{
    public string level { get; set; }
    public string key { get; set; }
    public string dsc { get; set; }
}

public class RootObject
{
    public string status { get; set; }
    public List<Message> messages { get; set; }
}

for JSON:

[{"level":"error","key":"InvalidTokenError","dsc":"Invalid token"}]

Type:

public class Message
    {
        public string level { get; set; }
        public string key { get; set; }
        public string dsc { get; set; }
    }
Sign up to request clarification or add additional context in comments.

Comments

2

You can use this site

public class Message
{
    public string level { get; set; }
    public string key { get; set; }
    public string dsc { get; set; }
}

public class RootObject
{
    public string status { get; set; }
    public List<Message> messages { get; set; }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.