this is the input
{ "product": [ { "name": "cake", "message": "Message1", "time":"2020-06-16" }, { "name": "apple", "message": "Message2", "time": "2020-06-16" }, { "name": "fish", "message": "Message4", "time": "2020-06-15" }, { "name": "toy", "message": "Message5", "time": "2020-06-15" }
] }
want this output below
[ { "time": "2020-06-16", "product": [ { "name": "cake", "message": "Message1" }, { "name": "apple", "message": "Message2" } ] }, { "time": "2020-06-15", "product": [ { "name": "fish", "message": "Message4' }, { "name": "toy", "message": "Message5" } ]
} ]
bez using plugin it tack some time
CodePudding user response:
final struct = <String, dynamic>{
{ "product": [ { "name": "cake", "message": "Message1", "time":"2020-06-16" }, { "name": "apple", "message": "Message2", "time": "2020-06-16" }, { "name": "fish", "message": "Message4", "time": "2020-06-15" }, { "name": "toy", "message": "Message5", "time": "2020-06-15" }
] }
};
and add what you need
struct["time"] = "2020-06-16";
CodePudding user response:
Follow the below.
List dataList=[];
var data={ "product": [ { "name": "cake", "message": "Message1", "time":"2020-06-16" }, { "name": "apple", "message": "Message2", "time": "2020-06-16" }, { "name": "fish", "message": "Message4", "time": "2020-06-15" }, { "name": "toy", "message": "Message5", "time": "2020-06-15" }
] };
In init call,
dataList.add(data);
Print result:
[ { "time": "2020-06-16", "product": [ { "name": "cake", "message": "Message1" }, { "name": "apple", "message": "Message2" } ] }, { "time": "2020-06-15", "product": [ { "name": "fish", "message": "Message4' }, { "name": "toy", "message": "Message5" } ]
} ]