我有一个像下面这样的 JSON 数据
[{"Staffs":[5,10,12,14]},{"Staffs":[11,13,15,17]}]
Run Code Online (Sandbox Code Playgroud)
我想从中提取价值并期待以下数据
[5,10,12,14,11,13,15,17]
Run Code Online (Sandbox Code Playgroud)
我怎样才能用 newtonsoft JSON 做到这一点。
您可以先将 JSON 解析为JArray:
using Newtonsoft.Json.Linq;
var array = JArray.Parse(yourJSONString);
Run Code Online (Sandbox Code Playgroud)
然后,使用SelectMany将其展平并将其转换为 a List<int>:
var result = array.SelectMany(x => x["Staffs"]).Values<int>().ToList();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
138 次 |
| 最近记录: |