json - 如何将 JSON 解析为 Dart 列表
问题描述
如何将复杂的 JSON 解析为 Darts/flutter 中的列表
我在地图中有消息,但我需要一些帮助来解析和获取值
这是 JSON:..
{
"jobs": [
{
"id": "S_1244",
"title": "Title1",
"location": {
"city": "Miami",
"stateCode": "FL"
},
"salary": {
"symbol": "US$",
"min": "26.15",
"max": "27.15"
},
"type": "Temporary",
"posted": 1530027914570
},
{
"id": "S_1234",
"title": "Title1",
"location": {
"city": "Miami",
"stateCode": "FL"
},
"salary": {
"symbol": "US$",
"min": "26.15",
"max": "27.15"
},
"type": "Temporary",
"posted": 1530027914570
}
]
}
我的身体在地图上
地图地图 = jsonDecode(data.body);
谢谢你的帮助
解决方案
您可以选择对 json 中的所有内容进行建模。这是开始的代码。
Map myMap = json.decode(response.body);
Iterable i = myMap['jobs'];
List<Jobs> jobs = i.map((model) => Jobs.fromJson(model)).toList();
}
class Jobs {
Jobs({this.id, this.title, this.type});
String id;
String title;
String type;
Jobs.fromJson(Map<String, dynamic> json)
: id = json['id'],
title = json['title'],
type = json['type'];
}
您将最终得到作业列表,这是您在 json 中的作业的普通旧 java 类表示。您也可以对位置和薪水进行建模。
推荐阅读
- c - 当我想更改变量的值时使用指针 *
- facebook - 如何在 OAuth 2.0 过程中自定义 Facebook 页面列表?
- python - 如何在 matplotlib 中使用日期时间标签标记毫秒轴
- v8 - 使用 GYP 构建 V8
- highcharts - 自动绘制累积数据
- excel - 语法错误 - 跨 2 个工作簿的 Excel VLookup
- python - Python / Folium / Choropleth:TypeError:不支持ufunc'isnan'
- python - 在 Databricks 上使用 Dask 和 fbprophet 会出错
- css - 标题生成器,全宽菜单颜色
- javascript - 材料 UI 数据网格复选框选择所有按钮在生产中不起作用