Facebook JSON 字符串的反序列化?

2024-03-29

我无法从运行 fql 查询后生成的 JSON 字符串中提取 facebook 用户的 work_history、从属关系和 current_loc

我已经上过这门课:

public class Data
{
    public CurrentLocation current_location { get; set; }
    public WorkHistory[] work_history { get; set; }
    public EducationHistory[] education_history { get; set; }
}

public class EducationHistory
{
    public string name { get; set; }
    public int? year { get; set; }
    public string school_type { get; set; }
}

public class WorkHistory
{
    public string company_name { get; set; }
    public Location location { get; set; }
}

public class CurrentLocation
{
    public string city { get; set; }
    public string state { get; set; }
    public string country { get; set; }
}

public class Location
{
    public string city { get; set; }
    public string state { get; set; }
}

我的 JSON 字符串的格式是:

   {"current_location":{"city":"Delhi","state":"Delhi","country":"India","zip":"","id":102161913158207,"name":"Delhi, India"}

,"education_history":[{"name":"I E T , Alwar (Raj.)","year":2007,"concentrations":[],"school_type":"College"},{"name":"Institute of Engineering and Technology, Alwar","concentrations":[],"school_type":"College"}],

"work_history": [{"location":{"city":"","state":""},"company_name":"Defence Research & Development Organisation (DRDO)","description":"","start_date":"0000-00","end_date":"0000-00"}]}

我如何提取这些数据当我使用此代码时,我得到一个空值:

Data soap = JsonConvert.DeserializeObject<Data>(ser);

编辑:我确实根据答案建议更改了代码,但我仍然没有得到任何值

Edit 2:如果我只有一个用户,那么提供的解决方案将会起作用,但是我有几个用户拥有这些详细信息,我如何获取这些数据?下面针对不同的用户给出了几个类似的值

   {
    "data": [
        {
            "uid": 54456565,
            "name": "dgfg Barma",
            "pic_square": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash2/275277_513046358_147089990_q.jpg",
            "affiliations": [
                {
                    "nid": 33605704,
                    "name": "Our Lady Queen of the Missions School",
                    "type": "high school"
                }
            ],
            "birthday_date": null,
            "sex": "female",
            "relationship_status": null,
            "current_location": {
                "city": "Delhi",
                "state": "Delhi",
                "country": "India",
                "zip": "",
                "id": 102161913158207,
                "name": "Delhi, India"
            },
            "education_history": [
                {
                    "name": "Amity University",
                    "concentrations": [],
                    "school_type": "College"
                },
                {
                    "name": "Amity School of Engineering & Technology",
                    "concentrations": [],
                    "school_type": "College"
                }
            ],
            "work_history": []
        },
        {
            "uid": 520310824,
            "name": "Mamta Meena",
            "pic_square": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-snc4/370835_520310824_553662476_q.jpg",
            "affiliations": [],
            "birthday_date": "12/03/1986",
            "sex": "female",
            "relationship_status": "Married",
            "current_location": {
                "city": "Delhi",
                "state": "Delhi",
                "country": "India",
                "zip": "",
                "id": 102161913158207,
                "name": "Delhi, India"
            },
            "education_history": [
                {
                    "name": "I E T , Alwar (Raj.)",
                    "year": 2007,
                    "concentrations": [],
                    "school_type": "College"
                },
                {
                    "name": "Institute of Engineering and Technology, Alwar",
                    "concentrations": [],
                    "school_type": "College"
                }
            ],
            "work_history": [
                {
                    "location": {
                        "city": "",
                        "state": ""
                    },
                    "company_name": "Defence Research & Development Organisation (DRDO)",
                    "description": "",
                    "start_date": "0000-00",
                    "end_date": "0000-00"
                }
            ]
        },
        {
            "uid": 6565767,
            "name": "gfgfg Agarwal",
            "pic_square": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash2/372433_529863326_1656605196_q.jpg",
            "affiliations": [
                {
                    "nid": 16827518,
                    "name": "Amity University",
                    "type": "college"
                }
            ],
            "birthday_date": "07/18",
            "sex": "female",
            "relationship_status": null,
            "current_location": {
                "city": "Delhi",
                "state": "Delhi",
                "country": "India",
                "zip": "",
                "id": 102161913158207,
                "name": "Delhi, India"
            },
            "education_history": [
                {
                    "name": "Amity University, Noida",
                    "year": 2012,
                    "concentrations": [],
                    "school_type": "College"
                },
                {
                    "name": "Amity University",
                    "concentrations": [],
                    "school_type": "Grad School"
                }
            ],
            "work_history": []
        },
        {
            "uid": 542580357,
            "name": "bnnm Gupta",
            "pic_square": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-snc4/372576_542580357_1330958366_q.jpg",
            "affiliations": [],
            "birthday_date": "04/30",
            "sex": "female",
            "relationship_status": "Single",
            "current_location": {
                "city": "New Delhi",
                "state": "Delhi",
                "country": "India",
                "zip": "",
                "id": 106517799384578,
                "name": "New Delhi, India"
            },
            "education_history": [
                {
                    "name": "Amity University",
                    "concentrations": [],
                    "school_type": "College"
                },
                {
                    "name": "Amity University, Noida",
                    "concentrations": [],
                    "school_type": "College"
                }
            ],
            "work_history": [
                {
                    "location": {
                        "city": "",
                        "state": ""
                    },
                    "company_name": "Oracle India Pvt Ltd",
                    "position": "Intern",
                    "description": "",
                    "start_date": "2011-05"
                }
            ]
        },
        {
            "uid": 544204117,
            "name": "pos Gupta",
            "pic_square": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-snc4/275346_544204117_594313449_q.jpg",
            "affiliations": [
                {
                    "nid": 16827518,
                    "name": "Amity University",
                    "type": "college"
                }
            ],
            "birthday_date": "05/17/1990",
            "sex": "female",
            "relationship_status": "Single",
            "current_location": {
                "city": "Noida",
                "state": "Uttar Pradesh",
                "country": "India",
                "zip": "",
                "id": 130646063637019,
                "name": "Noida, India"
            },
            "education_history": [
                {
                    "name": "Amity University, Noida",
                    "year": 2012,
                    "concentrations": [],
                    "school_type": "College"
                },
                {
                    "name": "Amity University",
                    "concentrations": [],
                    "school_type": "Grad School"
                }
            ],
            "work_history": []
        },
        {
            "uid": 4567786,
            "name": "orr Makhijani",
            "pic_square": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-snc4/372443_555253796_244086438_q.jpg",
            "affiliations": [
                {
                    "nid": 16827518,
                    "name": "Amity University",
                    "type": "college"
                }
            ],
            "birthday_date": null,
            "sex": "female",
            "relationship_status": null,
            "current_location": null,
            "education_history": [
                {
                    "name": "Amity University",
                    "concentrations": [],
                    "school_type": "College"
                }
            ],
            "work_history": []
        },
        {
            "uid": 556773604,
            "name": "Nazima Khalid",
            "pic_square": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash2/372542_556773604_1472126324_q.jpg",
            "affiliations": [],
            "birthday_date": "03/22",
            "sex": "female",
            "relationship_status": "Married",
            "current_location": {
                "city": "Toronto",
                "state": "Ontario",
                "country": "Canada",
                "zip": "",
                "id": 110941395597405,
                "name": "Toronto, Ontario"
            },
            "education_history": [
                {
                    "name": "AMU",
                    "concentrations": [],
                    "school_type": "College"
                }
            ],
            "work_history": [
                {
                    "location": {
                        "city": "Oakville",
                        "state": "Ontario"
                    },
                    "company_name": "SNC-Lavalin Inc.",
                    "position": "Contracts",
                    "description": "",
                    "start_date": "0000-00"
                }
            ]
        }
    ]
}

请帮忙


我不会声明很多小类,而是会去dynamic方式。这是代码动态 json 对象 http://pastebin.com/6b2fLChA。用法是这样的:

dynamic obj = JsonUtils.JsonObject.GetDynamicJsonObject(jsonString);

Console.WriteLine("{0} , {1}", obj.current_location.city, obj.current_location.state);

Console.WriteLine("EDUCATION");
foreach (var eduHist in obj.education_history)
{
    Console.WriteLine("{0} , {1}", eduHist.name, eduHist.year);
}

Console.WriteLine("WORK");
foreach (var workHist in obj.work_history)
{
    Console.WriteLine("{0}  {1}-{2}", workHist.company_name, workHist.start_date, workHist.end_date);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Facebook JSON 字符串的反序列化? 的相关文章

  • ASP.NET Web API 客户端 ProgressMessageHandler Post 任务卡在 WinForm 应用程序中

    我在用着HttpClient and ProgressMessageHandler来自MS ASP NET Web API 客户端库 http nuget org packages Microsoft AspNet WebApi Clien
  • 信号处理程序有单独的堆栈吗?

    信号处理程序是否有单独的堆栈 就像每个线程都有单独的堆栈一样 这是在 Linux C 环境中 来自 Linux 手册页signal 7 http kernel org doc man pages online pages man7 sign
  • 找不到 assimp-vc140-mt.dll ASSIMP

    我已经从以下位置下载了 Assimp 项目http assimp sourceforge net main downloads html http assimp sourceforge net main downloads html Ass
  • 类的成员复制

    在学习 复制成员 概念时 书中给出了如下说法 此外 如果非静态成员是引用 const 或没有复制赋值的用户定义类型 则无法生成默认赋值 我不太明白这个声明到底想传达什么 或者说这个说法指的是哪一种场景 谢谢 该语句与编译器自动为您编写的类
  • vs2008 c#:Facebook.rest.api如何使用它来获取好友列表?

    如何在此基础上取得进一步的进步 获取好友列表的下一步是什么 string APIKey ConfigurationManager AppSettings API Key string APISecret ConfigurationManag
  • 如何获取 QTableView 的标题列表?

    我有一个QTableView我的对话框中的对象 我需要访问该表的水平标题并将它们放入QStringList object 尽管进行了大量搜索 但我在 Qt 文档中找不到如何获取此标头列表 编辑 我发现的最接近的地方是this https w
  • 如何在 QTabWidget Qt 中展开选项卡

    我有一个QTabWidget像这个 但我想展开选项卡以 填充 整个小部件宽度 如下所示 我怎样才能做到这一点 我在用Qt 5 3 2 and Qt 创建者 3 2 1 Update 我尝试使用setExpanding功能 ui gt myT
  • 在 JSQMessagesViewController 中显示 LocationMediaItem

    我刚刚尝试实施LocationMediaItem in my Xamarin iOS应用程序使用JSQMessagesViewController 一切都很顺利 唯一的问题是UICollectionView应该显示位置的单元格永远停留在加载
  • Visual Studio Code:如何配置 includePath 以获得更好的 IntelliSense 结果

    我是使用 Visual Studio Code 的完全初学者 我不知道我在做什么 我已经四处搜索 也许还不够 但我找不到像我这样的人如何配置的简单解释c cpp properties json每当我单击带有绿色波浪线下划线的行旁边的黄色灯泡
  • std::forward_as_tuple 将参数传递给 2 个构造函数

    我想传递多个参数以便在函数内构造两个对象 以同样的方式std pair
  • C# 构建一个 webservice 方法,它接受 POST 方法,如 HttpWebRequest 方法

    我需要一个接受 POST 方法的 Web 服务 访问我的服务器正在使用 POST 方法 它向我发送了一个 xml 我应该用一些 xml 进行响应 另一方面 当我访问他时 我已经使用 HttpWebRequest 类进行了管理 并且工作正常
  • 如何通过 JsonConvert.DeserializeObject 在动态 JSON 中使用 null 条件运算符

    我正在使用 Newtonsoft 反序列化已知的 JSON 对象并从中检索一些值 如果存在 关键在于对象结构可能会不断变化 因此我使用动态来遍历结构并检索值 由于对象结构不断变化 我使用 null 条件运算符来遍历 JSON 代码看起来像这
  • 如何分析组合的 python 和 c 代码

    我有一个由多个 python 脚本组成的应用程序 其中一些脚本正在调用 C 代码 该应用程序现在的运行速度比以前慢得多 因此我想对其进行分析以查看问题所在 是否有工具 软件包或只是一种分析此类应用程序的方法 有一个工具可以将 python
  • ASP.NET MailMessage.BodyEncoding 和 MailMessage.SubjectEncoding 默认值

    很简单的问题 但我在 MSDN 上找不到答案 查找 ASP NET 将用于的默认值 MailMessage BodyEncoding and MailMessage SubjectEncoding 如果你不在代码中设置它们 Thanks F
  • C# 中的 strstr() 等效项

    我有两个byte 我想找到第二个的第一次出现byte 在第一个byte 或其中的一个范围 我不想使用字符串来提高效率 翻译第一个byte to a string会效率低下 基本上我相信就是这样strstr 在 C 中做 最好的方法是什么 这
  • IEnumerable.Except 不起作用,那么我该怎么办?

    我有一个 linq to sql 数据库 非常简单 我们有 3 个表 项目和用户 有一个名为 User Projects 的连接表将它们连接在一起 我已经有了一个获得的工作方法IEnumberable
  • 从 F# 调用 Newtonsoft.Json 出现意外结果

    我没有从该 F 代码中获得预期结果 我希望 t 包含调用 JsonSchema Parse json 的结果 但它是空的 我究竟做错了什么 open Newtonsoft Json open Newtonsoft Json Schema l
  • 使用taskkill停止Windows服务

    我需要帮助来使用 C 终止 Windows 服务 现在要终止该服务 请使用以下选项 从命令 sc queryex ServiceName 发现后PID服务的 taskkill pid 1234 exemple f 为了便于阅读 但如果您明白
  • 将 char[][] 转换为 char** 会导致段错误吗?

    好吧 我的 C 有点生疏了 但我想我应该用 C 来做我的下一个 小 项目 这样我就可以对其进行抛光 并且我已经有不到 20 行的段错误了 这是我的完整代码 define ROWS 4 define COLS 4 char main map
  • 使我的 COM 程序集调用异步

    我刚刚 赢得 了在当前工作中维护用 C 编码的遗留库的特权 这个dll 公开使用 Uniface 构建的大型遗留系统的方法 除了调用 COM 对象之外别无选择 充当此遗留系统与另一个系统的 API 之间的链接 在某些情况下 使用 WinFo

随机推荐