【发布时间】:2021-04-14 12:59:13
【问题描述】:
这是我的 json 数据结构:
[
[
{
"nos": 0,
"name": "A S MUSIC AND DANCE A CULTURAL ORGANIZATION",
"unique_id": "AN/2020/0259067",
"reg_details": [
{
"registered_with": "Registrar of Societies"
},
{
"type_of_ngo": "Registered Societies (Non-Government)"
},
{
"registration_no": "1534"
},
{
"copy_of_registration_certificate": "Available"
},
{
"copy_of_pan_card": "Available"
},
{
"date_of_registration": "25-05-2016"
}
],
我只想从日期键值与 年份 比较,即"date_of_registration": "25-05-2016"。
从小部件中获取值的我的按钮是:
RoundedButton(
text: "Next",
press: () async {
debugPrint(_currentValue.toString());
_NgoDetail(ngo,_currentValue.toString());
//Where _currentValue is actually the year I'm getting
//from a spinner widget
},
),
与这些值进行比较的函数是:
Future<bool> _NgoDetail(String name,String year) async { //Only Year as a
// parameter and not whole date
String jsonString = await _loadANgoAsset();
final jsonResponse = json.decode(jsonString);
int k=-2;
List<dynamic> allNamesOfNGO=jsonResponse[0];
allNamesOfNGO.takeWhile((value) => value != name).forEach((allNamesOfNGO){
(allNamesOfNGO as Map<String, dynamic>).forEach((key, value) {
++k;
if(key=='name' && value == name){
if(key=='date_of_registeration' && value == year) //Here value is
//complete date, I want
//it to be year only
{
Navigator.push(context,MaterialPageRoute(builder: (context)=> R3(jsonIndexOfNGO:k)));
}
}
else{
Fluttertoast.showToast(
msg: "Your given details doesn't match. Please try again",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 3,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0);
}
} );
});
}
我应该先在上面的函数中做什么?从 json 中检索所有日期值并将其格式从 25-02-2015 转换为 2015 或执行其他方法?
【问题讨论】: