gpt4 book ai didi

flutter - 从 Json 响应抖动中删除重复项

转载 作者:IT王子 更新时间:2023-10-29 07:15:29 30 4
gpt4 key购买 nike

我无法删除 Json 中的重复项。在下面的 Json 中,如果 title 字段具有相同的值,我需要删除重复的节点。在下面的名为“汽车”的 json 标题中重复了 3 次,我需要根据标题字段删除重复项。我按照下面的 stackoverflow 链接进行操作,但没有解决我的问题。

Remove duplicate value in dart

实际的 Json:

{
"totalSize": 6,
"done": true,
"records": [{
"attributes": {
"type": "ContentVersion",
"url": "https://sampleUrl"
},
"Id": "123456",
"Title": "car",
"Team_Category__c": "Vehicle"
},
{
"attributes": {
"type": "ContentVersion",
"url": "https://sampleUrl"
},
"Id": "123456",
"Title": "car",
"Team_Category__c": "Vehicle"
},

{
"attributes": {
"type": "ContentVersion",
"url": "https://sampleUrl"
},
"Id": "123456",
"Title": "cycle",
"Team_Category__c": "Vehicle"
},
{
"attributes": {
"type": "ContentVersion",
"url": "https://sampleUrl"
},
"Id": "123456",
"Title": "aeroplane",
"Team_Category__c": "Vehicle"
},
{
"attributes": {
"type": "ContentVersion",
"url": "https://sampleUrl"
},
"Id": "123456",
"Title": "car",
"Team_Category__c": "Vehicle"
}
]
}

最佳答案

kt_dart: 添加到您的 pubspec。

然后在你的dart文件中导入它import 'package:kt_dart/kt.dart';

然后:

var json = jsonDecode(yourJsonAsString);
var records = mutableListFrom(json["records"]);
var distinct = records.distinctBy((it) => it["Title"]);

关于flutter - 从 Json 响应抖动中删除重复项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57500645/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com