C#:Newtonsoft.Json将json字符串转换为实体对象

1.Json字符串:

{
  "OptTypeList": [
    [
      {
        "address": "宁波市鄞州区*****",
        "divisionName": "********",
        "tel": "010-12345678",
        "divisionId": "813402",
        "psummertime": "08:00",
        "pwintertime": "18:00",
        "streetId": "330212018"
      },
      {
        "address": "宁波市鄞州区********",
        "divisionName": "********",
        "divisionId": "811904",
        "streetId": "330212027"
      }
    ]
  ],
  "_TaskId": "53506a7943354748a1affdb9f635fb86",
  "_Return": "000000",
  "_ParentTaskId": "1f2bbefca759436a94017f55eed8512e"
}

2.打开网页,复制Json字符串,生成实体类

JSON转C#实体类-BeJSON.com

3.将生成的实体类加入项目代码;

4.引入Newtonsoft.Json.dll

Root root = JsonConvert.DeserializeObject<Root>(jsonString);
posted @ 2022-12-07 14:43  新*  阅读(2950)  评论(0编辑  收藏  举报