C#类解析JSON结果 [英] C# class to parse JSON result

查看:84
本文介绍了C#类解析JSON结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

应该如何使用c#类反序列化以下JSON字符串:

How should be a c# class to deserialize the folowing JSON string:

{
   "data": [
  {
 "id" : "id0012",
     "comments": {
        "data": [
           {
              "id": "123",
              "from": {
                 "name": "xpto",
                 "id": "5ddd"
              },
              "message": "tttt",
              "created_time": "2010-01-07T09:16:15+0000"
           },
           {
              "id": "222",
              "from": {
                 "name": "wwwww",
                 "id": "343434"
              },
              "message": "3333",
              "created_time": "2020-07-07T09:30:12+0000"
           }
        ],
        "paging": {
           "previous": "prevlink",
           "next": "nextLink"
        }
     }
  }

] }

谢谢

推荐答案

正如hangy所说,您当然可以使用Json.NET来解析该字符串.例如:

As hangy says, you can certainly use Json.NET to parse that string. For example:

using System;
using System.IO;
using Newtonsoft.Json.Linq;

namespace EvalTest
{
  public class Test
  {
    static void Main(string [] args)
    {
        string text = File.ReadAllText("test.txt");
        var json = JObject.Parse(text);

        var data = json["data"];
        Console.WriteLine((string) data[0]["id"]);
    }
  }
}

如果您需要更多帮助,则应该提出更具体的问题.

If you need more help, you should ask a more specific question.

这篇关于C#类解析JSON结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆