SajjadZare SajjadZare - 4 months ago 8x
JSON Question

Json.NET failes to deserialize Json to a field-only class

I want to parse a piece of JSON with Newtonsoft Json.NET



"result_description":"NET Connections",



public class USER
public string result_id;
public string result_description;
public string[] cmlog_username;
public string[] caller_id;

I convert it with below code but all of property value is NULL

USER con = JsonConvert.DeserializeObject<USER>(msg);


Your deserialization class is incorrect. Putting your JSON into produces:

public class USER
    public string result_id { get; set; }
    public string result_description { get; set; }
    public List<string> cmlog_username { get; set; }
    public List<string> caller_id { get; set; }

public class RootObject
    public USER USER { get; set; }

So you would need to do:

User con = JsonConvert.DeserializeObject<RootObject>(msg);

Your JSON object isn't a USER, it's an object that contains a USER.