【发布时间】:2014-03-29 23:58:35
【问题描述】:
我正在尝试反序列化从休息服务(使用 RestSharp)获得的 json 响应,但我不断收到此错误:
无法将“RestSharp.JsonArray”类型的对象转换为“System.Collections.Generic.IDictionary`2[System.String,System.Object]”类型。
响应如下所示:
“message” : “Successfully authenticated.”,
“total” : null,
“data” : [ {
“token” : “XYZ”,
“user” : {
“password” : “ABC”,
“username” : “User”
}
}],
“success” : true
我创建了以下 C# 对象:
internal class AuthenticationResponse
{
public string message { get; set; }
public string total { get; set; }
public AuthenticationResponseData data { get; set; }
public bool success {get;set;}
}
internal class AuthenticationResponseData
{
public string token { get; set; }
public AuthenticationUser user {get;set;}
}
internal class AuthenticationUser
{
public string username {get;set;}
public string password {get;set;}
}
但我不断收到以下错误:
无法将“RestSharp.JsonArray”类型的对象转换为“System.Collections.Generic.IDictionary`2[System.String,System.Object]”类型。
【问题讨论】: