简体   繁体   English

如何在 c# 3.5 框架中从 JSON 中获取所有值?

[英]How to get all values from JSON in c# 3.5 framework?

Below is my JSON response.下面是我的 JSON 响应。 I want to fetch orderid , caseid each filed one by one and their value.我想获取orderidcaseid每个都一一提交及其价值。

"cases": [
  {
    "status": "DISMISSED",
    "createdAt": "2015-09-18T08:56:04+0000",
    "investigationId": 19246020,
    "caseId": 19246020,
    "score": 794.6295793608853,
    "adjustedScore": 794.6295793608853,
    "updatedAt": "2015-09-18T08:56:05+0000",
    "headline": "Steven Rusk",
    "orderId": "116588",
    "orderDate": "",
    "orderAmount": 425.0,
    "associatedTeam": {
      "teamName": "B2C Jewels",
      "teamId": 4289
    },
    "reviewDisposition": null,
    "uuid": "5821ed91-5f8f-4b51-bd63-a8834f2a95b3"
  },
  {
    "status": "DISMISSED",
    "createdAt": "2015-09-16T11:33:28+0000",
    "investigationId": 19114061,
    "caseId": 19114061,
    "score": 241.65405995385285,
    "adjustedScore": 241.65405995385285,
    "updatedAt": "2015-09-18T19:07:51+0000",
    "headline": "221.134.83.50",
    "orderId": "101",
    "orderDate": "2015-09-16T17:07:30+0000",
    "orderAmount": 9.99,
    "associatedTeam": {
      "teamName": "B2C Jewels",
      "teamId": 4289
    },
    "reviewDisposition": null,
    "uuid": "301f2cfc-3b67-4fc0-bf83-19099c2ea4bf"
  },
]

您将必须创建一个名为 case 的类,然后您需要将您的 json 映射到列表,然后您可以遍历列表,希望它对您有用。

 List<cases> = new JavaScriptSerializer().Deserialize<List<cases>>(your json string);

You can install Json.Net package from Nuget and then add this line of code in you project您可以从 Nuget 安装 Json.Net 包,然后在您的项目中添加这行代码

var myList = Newtonsoft.Json.JsonConvert.DeserializeObject("Your Json String..!!");

this should do it这应该这样做

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM