我有一个 JSON 编码的字符串。它看起来像这样:
{"jsonrpc":"2.0","method":"test","params":["80851851709e01bc9453cced585a7bca","this"],"id":3}
出于某种原因,我无法使用 C# 访问“params”。该对象返回 null。这是我正在使用的代码:
public class Access : System.Web.Services.WebService
{
[WebMethod]
public string EntryMethod(string json)
{
Requests d = JsonConvert.DeserializeObject<Requests>(json);
return "done";
}
}
public class Requests
{
public string jsonrpc { get; set; }
public string method { get; set; }
public List<string> param { get; set; }
public string id { get; set; }
}
有什么想法吗?
最佳答案
由于打字错误,应该是:
ParamS // Add one more S
所以,你的类(class)应该是:
public class Requests
{
public string jsonrpc { get; set; }
public string method { get; set; }
public List<string> @params { get; set; }
public string id { get; set; }
}
关于C# Json.Net - 如何反序列化复杂对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12711407/