Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用json.net在c#中反序列化json对象_C#_Json_Json.net_Deserialization - Fatal编程技术网

使用json.net在c#中反序列化json对象

使用json.net在c#中反序列化json对象,c#,json,json.net,deserialization,C#,Json,Json.net,Deserialization,我在反序列化从Web服务器获得的一些json时遇到了一个问题,我认为这是因为格式化的缘故 json格式如下所示: { "post_count": { "total_posts": 1, "sfw_total_posts": 1, "use": 0 }, "posts_per_page": 1, "posts": [ { "guid": 10019127,

我在反序列化从Web服务器获得的一些json时遇到了一个问题,我认为这是因为格式化的缘故

json格式如下所示:

{
    "post_count": {
        "total_posts": 1,
        "sfw_total_posts": 1,
        "use": 0
    },
    "posts_per_page": 1,
    "posts": [
        {
            "guid": 10019127,
            "wp_id": 656197,
            "type": "media",
            "title": "Test",
            "path": "TestPath",
            "publish_start": 1385559021,
            "author": "Test",
            "web_url": "http://www.test.com",
            "nsfw": "No",
            "modified": 1385532803,
            "video": "No",
            "likes": 484,
            "dislikes": 51,
            "main_category_id": 71,
            "thumbnails": [
                {
                    "w": 120,
                    "h": 120
                },
                {
                    "w": 240,
                    "h": 240
                }
            ],
            "comments": 26
        }
    ],
    "server": "100.200",
    "time": 0.42163896560669
}
我已经创建了一个类,它的值是我想要使用的,然后使用

LatestChive lastchives = JsonConvert.DeserializeObject<LatestChive>(jsonstring);
LatestChive lastchives=JsonConvert.DeserializeObject(jsonstring);
我尝试反序列化它,但所有值都返回null(我只想要“posts”中的内容)

如果我尝试使用“post\u count”或“posts\u per\u page”,我可以从“posts”中获取值

我希望这是有意义的,并且有一个简单的解决方法,谢谢。

将您的类定义为

public class PostCount
{
    public int total_posts { get; set; }
    public int sfw_total_posts { get; set; }
    public int use { get; set; }
}

public class Thumbnail
{
    public int w { get; set; }
    public int h { get; set; }
}

public class Post
{
    public int guid { get; set; }
    public int wp_id { get; set; }
    public string type { get; set; }
    public string title { get; set; }
    public string path { get; set; }
    public int publish_start { get; set; }
    public string author { get; set; }
    public string web_url { get; set; }
    public string nsfw { get; set; }
    public int modified { get; set; }
    public string video { get; set; }
    public int likes { get; set; }
    public int dislikes { get; set; }
    public int main_category_id { get; set; }
    public List<Thumbnail> thumbnails { get; set; }
    public int comments { get; set; }
}

public class LatestChive
{
    public PostCount post_count { get; set; }
    public int posts_per_page { get; set; }
    public List<Post> posts { get; set; }
    public string server { get; set; }
    public double time { get; set; }
}
公共类后计数
{
公共整数总计{get;set;}
public int sfw_total_posts{get;set;}
公共int使用{get;set;}
}
公共类缩略图
{
公共整数w{get;set;}
公共int h{get;set;}
}
公营职位
{
公共int guid{get;set;}
公共int wp_id{get;set;}
公共字符串类型{get;set;}
公共字符串标题{get;set;}
公共字符串路径{get;set;}
public int publish_start{get;set;}
公共字符串作者{get;set;}
公共字符串web_url{get;set;}
公共字符串nsfw{get;set;}
公共int修改{get;set;}
公共字符串视频{get;set;}
公共int类{get;set;}
公共int不喜欢{get;set;}
public int main_category_id{get;set;}
公共列表缩略图{get;set;}
公共int注释{get;set;}
}
公营晚香葱
{
公共后计数后计数{get;set;}
公共整型贴子每个页面{get;set;}
公共列表发布{get;set;}
公共字符串服务器{get;set;}
公共双时间{get;set;}
}
有关将来的工作,请参见将类定义为

public class PostCount
{
    public int total_posts { get; set; }
    public int sfw_total_posts { get; set; }
    public int use { get; set; }
}

public class Thumbnail
{
    public int w { get; set; }
    public int h { get; set; }
}

public class Post
{
    public int guid { get; set; }
    public int wp_id { get; set; }
    public string type { get; set; }
    public string title { get; set; }
    public string path { get; set; }
    public int publish_start { get; set; }
    public string author { get; set; }
    public string web_url { get; set; }
    public string nsfw { get; set; }
    public int modified { get; set; }
    public string video { get; set; }
    public int likes { get; set; }
    public int dislikes { get; set; }
    public int main_category_id { get; set; }
    public List<Thumbnail> thumbnails { get; set; }
    public int comments { get; set; }
}

public class LatestChive
{
    public PostCount post_count { get; set; }
    public int posts_per_page { get; set; }
    public List<Post> posts { get; set; }
    public string server { get; set; }
    public double time { get; set; }
}
公共类后计数
{
公共整数总计{get;set;}
public int sfw_total_posts{get;set;}
公共int使用{get;set;}
}
公共类缩略图
{
公共整数w{get;set;}
公共int h{get;set;}
}
公营职位
{
公共int guid{get;set;}
公共int wp_id{get;set;}
公共字符串类型{get;set;}
公共字符串标题{get;set;}
公共字符串路径{get;set;}
public int publish_start{get;set;}
公共字符串作者{get;set;}
公共字符串web_url{get;set;}
公共字符串nsfw{get;set;}
公共int修改{get;set;}
公共字符串视频{get;set;}
公共int类{get;set;}
公共int不喜欢{get;set;}
public int main_category_id{get;set;}
公共列表缩略图{get;set;}
公共int注释{get;set;}
}
公营晚香葱
{
公共后计数后计数{get;set;}
公共整型贴子每个页面{get;set;}
公共列表发布{get;set;}
公共字符串服务器{get;set;}
公共双时间{get;set;}
}
有关将来的工作,请参见将类定义为

public class PostCount
{
    public int total_posts { get; set; }
    public int sfw_total_posts { get; set; }
    public int use { get; set; }
}

public class Thumbnail
{
    public int w { get; set; }
    public int h { get; set; }
}

public class Post
{
    public int guid { get; set; }
    public int wp_id { get; set; }
    public string type { get; set; }
    public string title { get; set; }
    public string path { get; set; }
    public int publish_start { get; set; }
    public string author { get; set; }
    public string web_url { get; set; }
    public string nsfw { get; set; }
    public int modified { get; set; }
    public string video { get; set; }
    public int likes { get; set; }
    public int dislikes { get; set; }
    public int main_category_id { get; set; }
    public List<Thumbnail> thumbnails { get; set; }
    public int comments { get; set; }
}

public class LatestChive
{
    public PostCount post_count { get; set; }
    public int posts_per_page { get; set; }
    public List<Post> posts { get; set; }
    public string server { get; set; }
    public double time { get; set; }
}
公共类后计数
{
公共整数总计{get;set;}
public int sfw_total_posts{get;set;}
公共int使用{get;set;}
}
公共类缩略图
{
公共整数w{get;set;}
公共int h{get;set;}
}
公营职位
{
公共int guid{get;set;}
公共int wp_id{get;set;}
公共字符串类型{get;set;}
公共字符串标题{get;set;}
公共字符串路径{get;set;}
public int publish_start{get;set;}
公共字符串作者{get;set;}
公共字符串web_url{get;set;}
公共字符串nsfw{get;set;}
公共int修改{get;set;}
公共字符串视频{get;set;}
公共int类{get;set;}
公共int不喜欢{get;set;}
public int main_category_id{get;set;}
公共列表缩略图{get;set;}
公共int注释{get;set;}
}
公营晚香葱
{
公共后计数后计数{get;set;}
公共整型贴子每个页面{get;set;}
公共列表发布{get;set;}
公共字符串服务器{get;set;}
公共双时间{get;set;}
}
有关将来的工作,请参见将类定义为

public class PostCount
{
    public int total_posts { get; set; }
    public int sfw_total_posts { get; set; }
    public int use { get; set; }
}

public class Thumbnail
{
    public int w { get; set; }
    public int h { get; set; }
}

public class Post
{
    public int guid { get; set; }
    public int wp_id { get; set; }
    public string type { get; set; }
    public string title { get; set; }
    public string path { get; set; }
    public int publish_start { get; set; }
    public string author { get; set; }
    public string web_url { get; set; }
    public string nsfw { get; set; }
    public int modified { get; set; }
    public string video { get; set; }
    public int likes { get; set; }
    public int dislikes { get; set; }
    public int main_category_id { get; set; }
    public List<Thumbnail> thumbnails { get; set; }
    public int comments { get; set; }
}

public class LatestChive
{
    public PostCount post_count { get; set; }
    public int posts_per_page { get; set; }
    public List<Post> posts { get; set; }
    public string server { get; set; }
    public double time { get; set; }
}
公共类后计数
{
公共整数总计{get;set;}
public int sfw_total_posts{get;set;}
公共int使用{get;set;}
}
公共类缩略图
{
公共整数w{get;set;}
公共int h{get;set;}
}
公营职位
{
公共int guid{get;set;}
公共int wp_id{get;set;}
公共字符串类型{get;set;}
公共字符串标题{get;set;}
公共字符串路径{get;set;}
public int publish_start{get;set;}
公共字符串作者{get;set;}
公共字符串web_url{get;set;}
公共字符串nsfw{get;set;}
公共int修改{get;set;}
公共字符串视频{get;set;}
公共int类{get;set;}
公共int不喜欢{get;set;}
public int main_category_id{get;set;}
公共列表缩略图{get;set;}
公共int注释{get;set;}
}
公营晚香葱
{
公共后计数后计数{get;set;}
公共整型贴子每个页面{get;set;}
公共列表发布{get;set;}
公共字符串服务器{get;set;}
公共双时间{get;set;}
}

关于你未来的工作,请参见

展示你的
LatestChive
类会有所帮助。展示你的
LatestChive
类会有所帮助。展示你的
LatestChive
类会有所帮助。展示你的
LatestChive
类会有所帮助。