c# - 我如何解析json?

标签 c# json

<分区>

我正在使用 Newtonsoft Json 库来解析 json,但我不知道如何使用它。我使用 JObject 解析了字符串。当我在即时窗口中输出 JObject 实例的值时,我得到了这个:-

json
{
  "data": [
    {
      "id": "id",
      "from": {
        "name": "name",
        "id": "someotherid"
      },
      "name": "pic",
      "description": "desc",
      "link": "linktosite",
      "privacy": "everyone",
      "count": 1,
      "type": "normal",
      "created_time": "2010-10-22T14:54:32+0000",
      "updated_time": "2010-10-22T14:55:41+0000"
    },
    {
      "id": "id2",
      "from": {
        "name": "name",
        "id": "someotherid"
      },
      "name": "Profile Pictures",
      "link": "link",
      "privacy": "everyone",
      "count": 6,
      "type": "profile",
      "created_time": "2010-10-12T14:27:58+0000",
      "updated_time": "2011-01-01T18:38:14+0000"
    },
    {
      "id": "id3",
      "from": {
        "name": "name",
        "id": "829741958"
      },
      "name": "T",
      "link": "link",
      "privacy": "everyone",
      "count": 5,
      "type": "normal",
      "created_time": "2010-05-01T03:03:39+0000",
      "updated_time": "2010-05-01T03:19:13+0000",
      "comments": {
        "data": [
          {
            "id": "id",
            "from": null,
            "message": "message",
            "created_time": "2010-08-28T18:27:10+0000",
            "likes": 1
          }
        ]
      }
    }
  ],
  "paging": {
    "previous": "paginglink",
    "next": "otherpaginglink"
  }
}

    Count: 2
    Type: Object

我应该怎么做才能从这个工作项目中获得值(value)?

最佳答案

我个人更喜欢 JavaScriptSerializer用于 .NET 环境中的 JSON。默认情况下,它将返回字典结果,但可用于解析为自定义对象(或者您可以使用动态数据类型)。

Some other posts on SO with JSON & JavaScript Serializer as topic

关于c# - 我如何解析json?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4929434/

相关文章:

ios - iTunes API - JSON 数组错误 Swift4,要求。在 Collection View 中显示为数组

json - 在 PostgreSQL 9.2 中的 json 字段上创建索引

c# - 字符串连接是否在内部使用 StringBuilder?

c# - 是否可以通过 Internet 调试 Windows 桌面应用程序?

c# - 实际上什么是Nothing——它是如何转换的

javascript - 作用域函数不适用于 JSON 对象

javascript Json解析错误Doubleqoutes

c# - 正则表达式:查找以下一个单词开头的相同字母结尾的单词

c# - 服务器无法验证请求

javascript - 按描述过滤 JSON 对象 Express JS/Underscore JS