解析json数据字符串存储在数组中

kir*_*ran 0 c# arrays json ios xamarin

下面是解析的 json 数据,其类型为string.

\n\n
  "data": [\n    {\n      "Company": {\n        "id": "1",\n        \xe2\x80\x9cValue": \xe2\x80\x9c20\xe2\x80\x9d,\n        "companyId": "2001\xe2\x80\x9d,\n      }\n    },\n    {\n      "Company": {\n        "id": "2",\n        \xe2\x80\x9cvalue\xe2\x80\x9d: "20\xe2\x80\x9d,\n        "companyId\xe2\x80\x9d: "2002\xe2\x80\x9d,\n      }\n    },\n    {\n      "Company": {\n        "id": \xe2\x80\x9c3\xe2\x80\x9d,\n        \xe2\x80\x9cvalue\xe2\x80\x9d: \xe2\x80\x9c30\xe2\x80\x9d,\n        "companyId\xe2\x80\x9d: "2003\xe2\x80\x9d,\n      }\n    },\n ]\n\nvar parseData = Newtonsoft.Json.Linq.JObject.Parse (e.ResponseData.ToString ());\n
Run Code Online (Sandbox Code Playgroud)\n\n

转换json数据字符串存储在数组中,存储公司值的Arraylist。\n这是第一次处理Json对象字符串。

\n

Mik*_*ala 5

string json = @"{
      'status_code': 200,
      'status_text': 'matches found',
      'data': [{
         'company': {
           'id': '1',
           'value': '20',
           'companyId': '2001',}
         },
         {
         'company': {
           'id': '2',
           'value': '20',
           'companyId': '2002',}
         },
         {
         'company': {
           'id': '3',
           'value': '30',
           'companyId': '2003',}
         },]
       }";

JObject jObj = JObject.Parse(json);
var ids = jObj["data"].Children()["company"]["companyId"];
var list = new List<string>();
list.AddRange(ids.Select(id => id.Value<string>()));

foreach (var item in list)
    Console.WriteLine(item);

// Outputs ->
//  2001
//  2002
//  2003
Run Code Online (Sandbox Code Playgroud)

编辑:

公司的“一切”列表:

JObject jObj = JObject.Parse(json);
var jEnum = jObj["data"].Children()["company"];

var list = jEnum.Select(company => 
    company.Values().Select(current => 
        current.Value<string>()).ToList()).ToList();
Run Code Online (Sandbox Code Playgroud)