【问题标题】:Facebook Json Deserialize C# data fromFacebook Json 反序列化来自的 C# 数据
【发布时间】:2014-01-09 07:36:42
【问题描述】:

Facebook Json 反序列化来自

的 C# 数据
    "comments": {
      "data": [
        {
          "id": "10202845951538899_6903133", 
          "from": {
            "name": "Name Surname", 
            "id": "1514294282"
          }, 
          "message": "Statuses Comment", 
          "can_remove": true, 
          "created_time": "2013-12-11T15:49:35+0000", 
          "like_count": 0, 
          "user_likes": false
        }
      ]

如何从 id name 访问 json 评论数据

谢谢。

【问题讨论】:

标签: c# json facebook-graph-api import deserialization


【解决方案1】:

使用 Newtonsoft Json 反序列化为 C# 类的简单示例。

如果您没有此软件包,请使用 Nuget 进行安装:

Install-Package Newtonsoft.Json

Program.cs(控制台应用)

using Newtonsoft.Json;
using System;
using System.Collections.Generic;

namespace test
{

    public class FbData
    {
        public string id { get; set; }
        public FbCommentBy from { get; set; }
        public string message { get; set; }
        public string can_remove { get; set; }
    }

    public class FbCommentBy
    {
        public string name { get; set; }
        public string id { get; set; }
    }

    public class FbComments
    {
        public List<FbData> data { get; set; }
    }

    public class FbWrapper
    {
        public FbComments comments { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {

            string fbJson = @"{
   'comments':{
      'data':[
         {
            'id':'10202845951538899_6903133',
            'from':{
               'name':'Name Surname',
               'id':'1514294282'
            },
            'message':'Statuses Comment',
            'can_remove':true,
            'created_time':'2013-12-11T15:49:35+0000',
            'like_count':0,
            'user_likes':false
         }
      ]
   }
}";

            FbWrapper wrapper = JsonConvert.DeserializeObject<FbWrapper>(fbJson);

        }
    }
}

【讨论】:

  • 感谢您的回复,但我正在使用 Facebook 数据
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-09
  • 2016-05-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多