kir*_*ran 0 c# arrays json ios xamarin
下面是解析的 json 数据,其类型为string.
"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 ());\nRun Code Online (Sandbox Code Playgroud)\n\n转换json数据字符串存储在数组中,存储公司值的Arraylist。\n这是第一次处理Json对象字符串。
\nstring 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)
| 归档时间: |
|
| 查看次数: |
18017 次 |
| 最近记录: |