小编Cro*_*ems的帖子

在c#中使用索引数组反序列化JSON

我很擅长使用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)

c# asp.net-mvc json deserialization

7
推荐指数
1
解决办法
1078
查看次数

标签 统计

asp.net-mvc ×1

c# ×1

deserialization ×1

json ×1