我想在“EngName”列表中获得“曼谷”的值
x1c 0d1x->这是我的JSON数据
这是我的dart代码:
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_report/RainfallThai.dart';
import 'package:http/http.dart' as http;
import 'package:syncfusion_flutter_charts/charts.dart';
class LineCharts extends StatefulWidget {
const LineCharts({super.key});
@override
State<LineCharts> createState() => _DashBoardDBState();
}
class _DashBoardDBState extends State<LineCharts> {
List<RainfallThai> usersA = [];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Line Charts"),
backgroundColor: Colors.pink[300],
),
body: Container(
child: SfCartesianChart(
primaryXAxis: CategoryAxis(),
title: ChartTitle(text: 'ปริมาณน้ำฝน'),
legend: Legend(
isVisible: true,
),
tooltipBehavior: TooltipBehavior(enable: true),
series: <ChartSeries<RainfallThai, String>>[
LineSeries<RainfallThai, String>(
dataSource: usersA,
xValueMapper: (RainfallThai monthai, _) => monthai.MonThai,
yValueMapper: (RainfallThai avgrain, _) =>
num.tryParse(avgrain.AvgRain),
dataLabelSettings: DataLabelSettings(isVisible: true),
),
]),
),
floatingActionButton: FloatingActionButton(
onPressed: fetchUsersA,
backgroundColor: Colors.amber,
child: Icon(Icons.auto_graph_rounded),
),
);
}
@override
void initState() {
super.initState();
fetchUsersA();
}
void fetchUsersA() async {
print('LINE CHART called');
const urlA = "https://v1.nocodeapi.com/synatic/csv2json/pOWwVHFulerJvWnC";
final uriA = Uri.parse(urlA);
final responseA = await http.get(uriA);
final bodyA = responseA.body;
final jsonsA = jsonDecode(bodyA);
final jsonA = jsonsA['json'] as List<dynamic>;
final transformedA = jsonA.map((obj) {
print(obj['EngName']);
return RainfallThai(
ProvinceName: '',
EngName: obj['EngName'],
toID: '',
MonThai: obj['MonThai'],
MinRain: '',
MaxRain: '',
AvgRain: obj['AvgRain'],
region: '',
Year: obj['Year'],
Month: '',
Date: '');
}).toList();
setState(() {
usersA = transformedA;
});
print('LINE CHART completed');
}
}
字符串
这就是->的输出
print(obj['EngName']);
型
输出
->打印输出图像
总之,我想知道如何输出,只显示值的子列表,
扑:曼谷
并非子列表中的所有数据
1条答案
按热度按时间e3bfsja21#
更改此行
字符串
到
型