0

如何为此json创建模型?

{"code":"1", "message":"OK","re​​sponse": {"user":{"id":"124","usertype":"29","currenttime":"2013- 04-24T08:09:20.487+00:00","sessionid":"2bcf1c92-9b97-47d8-8995-b39cf7cbe2af"}}}

我写的:

public class BaseResponse
    {
        public bool success;
        public String message;
    }

    public class CreateTaskResponse : BaseResponse
    {
        CreateTaskResponseData data = new CreateTaskResponseData();

        public User getUser()
        {
            return data.getUser();
        }
    }

    class CreateTaskResponseData
    {
        User user = new User();
        public User getUser()
        {
            return user;
        }
    }

public class User
{
    public int id;
    public int usertype;
    public string currenttime;
    public string sessionid;
}

并解析:

CreateTaskResponse Login = SimpleDataSerializer.ToObject<CreateTaskResponse>(response);

错误:Login.getUser().sessionid 为空

4

1 回答 1

3

这是本站生成的

public class User
{
    public string id { get; set; }
    public string usertype { get; set; }
    public string currenttime { get; set; }
    public string sessionid { get; set; }
}

public class Response
{
    public User user { get; set; }
}

public class RootObject
{
    public string code { get; set; }
    public string message { get; set; }
    public Response response { get; set; }
}

var obj = JsonConvert.DeserializeObject<RootObject>(json);
于 2013-04-24T08:39:34.010 回答