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 が null です

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 に答える