0

我尝试反序列化这个 json 字符串

{"errors":null,"value":{
    "APIVersion":"0.0.1",
    "resturantName":"Imperial Lanes",
    "serverVersion":"4.3.133",
    "user{
        "authorities":null,
        "barCode":11,
        "firstname":"Admin",
        "identifier":1,
        "lastname":"-"
         }
     }
 }

使用

Result<LoginResponse> loginResponse = 
    jsonSerialiser.Deserialize<Result<LoginResponse>>(Response);

其中 Response 是我的 json 字符串,但我得到错误:没有为类型定义的无参数构造函数...

我的课看起来像这样

[DataContract]
public class Result<T>
{
    public Result(T value, ErrorMessage errors)
    {
        this.value = value;
        this.errors = errors;
    }

    [DataMember]
    public T value { get; private set; }

    [DataMember]
    public ErrorMessage errors { get; private set; }
}

public class LoginResponse
{
    public string serverVersion;
    public string APIVersion; // "0.0.1"
    public string resturantName;
    public User user = new User();
}

public class User
{
    public long identifier;
    public long barCode;
    public string firstname;
    public string lastname;
    public List<string> authorities;
}
4

1 回答 1

0

使用相同的类和相同的 jsonstring尝试了http://james.newtonking.com/projects/json-net.aspx json.net,它运行良好。

于 2013-08-05T13:45:42.287 回答