Add json values in to the list of object
171
Assuming you've a JSON file, which you may have parsed like this:
String json = await rootBundle.loadString('file_name.json');
var response = jsonDecode(json);
This is how you can do it:
List<dynamic> jsonData; //similar to var jsonData = [something, something, ...]
//traversing through each value in the key value arrangement of the json
for (var k in response.values) {
jsonData.add(k); //adding each value to the list
}
After the loop ends, jsonData
will have all the values of your JSON file.
Author by
Masoud H
Updated on January 02, 2023Comments
-
Masoud H over 1 year
How I can get all the values in this JSON and add all the value in to the list of object in the dart?
"data": [ { "$id": "2", "serviceId": 1017, "name": "اکو", "code": "235", "price": 1562500, "isDefault": true, "transportCostIncluded": false, "qty": 0, "minQty": 1, "maxQty": 2, "description": "یک دستگاه اکو به همراه دو باند و یک عدد میکروفن (تامین برق بعهده پیمانکار می باشد).", "contractorSharePercent": 65, "unitMeasureId": 7, "unitMeasureName": "هر 60 دقیقه", "superContractorsId": null }, ],
like this
var list = ["2",1017,....]