我有以下的JSON响应,我试图将其反序列化为C#对象,但我一直收到错误信息。 JSON响应:
"\"{\\\"method\\\":\\\"https://hereisalink.com\\\",\\\"http_method\\\":\\\"POST\\\",\\\"http_code\\\":900,\\\"error_code\\\":\\\"OK\\\",\\\"error_msg\\\":\\\"\\\",\\\"params\\\":[],\\\"data\\\":{\\\"summaryUrl\\\":\\\"https://sureyurl.com/?firstparam=123&secondparam=myemail%40gmail%2Ecom\\\",\\\"my_id\\\":1234,\\\"myemail\\\":\\\"theemail@gmail.com\\\",\\\"result\\\":\\\"yes\\\"}}\""
我的C#对象:
public class SummaryOBJ
{
public string method { get; set; }
public string http_method { get; set; }
public string POST { get; set; }
public string http_code { get; set; }
public string error_code { get; set; }
public string error_msg { get; set; }
public string[] @params { get; set; }
public Thesummary data { get; set; }
}
public class Thesummary
{
public string summaryUrl { get; set; }
public int my_id { get; set; }
public string myemail { get; set; }
public string result { get; set; }
}
我的C#反序列化代码:
//var myresp is the above json response i mention
var myresult = JsonConvert.DeserializeObject<SummaryOBJ>(myresp);
我收到的错误信息:
无法将值“{"method":"https://hereisalink.com","http_method":"POST","http_code":900,"error_code":"OK","error_msg":"","params":[],"data":{"summaryUrl":"https://sureyurl.com/?firstparam=123&secondparam=myemail%40gmail%2Ecom","my_id":1234,"myemail":"theemail@gmail.com","result":"yes"}}"转换为类型'SummaryOBJ'。路径'',第1行,第383个位置。
@params
属性类型从string[]
更改为List<string>
。 - vasily.sibhttp_code
成字符串,所以不会是那个问题。这里有一个可用的 dotnetfiddle。 - Kirk Larkin