我很擅长使用JSON,并且正在处理从API返回,我无法更改格式.返回示例是:(已删除实际网址)
{
"body":
{
"link":
{"linkurl": ["www.google.com"]}
},
"error": null,
"message": "Data Retrieved successfully",
"status": true
}
Run Code Online (Sandbox Code Playgroud)
我在VS2010中使用带有MVC 3的Newtonsoft.Json库.
我的班级是:
[JsonObject(MemberSerialization.OptIn)]
public class LinksJSON
{
[JsonProperty]
public string link{ get; set; }
[JsonProperty]
public string message { get; set; }
[JsonProperty]
public string error { get; set; }
[JsonProperty]
public bool status { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我用以下方法对其进行反序列化:
private static T _download_serialized_json_data<T>(string url) where T : new()
{
using (var w = new WebClient())
{
var json_data = string.Empty;
// …Run Code Online (Sandbox Code Playgroud)