I have a Json parsing project in Flutter and the Json is as follows:
{
\"Dependents\":[
{
\"Name\": \"Kim\",
\"Relationship\": \"Pare
You have information there : http://cogitas.net/parse-json-dart-flutter/
Example from the page :
void _parseJsonForCrossword(String jsonString) {
Map decoded = JSON.decode(jsonString);
String name = decoded['name'];
print(name);
int id = decoded['id'];
print(id.toString());
for (var word in decoded['across']) {
print(word['number'].toString());
print(word['word']);
}
}
You could use the following snippet:
void iterateJson(String jsonStr) {
Map<String, dynamic> myMap = json.decode(jsonStr);
List<dynamic> entitlements = myMap["Dependents"][0]["Entitlements"];
entitlements.forEach((entitlement) {
(entitlement as Map<String, dynamic>).forEach((key, value) {
print(key);
(value as Map<String, dynamic>).forEach((key2, value2) {
print(key2);
print(value2);
});
});
});
}
Although you could possibly simplify a little the 'entitlements' field if you don't care about the order by removing the list and leaving just one map:
"Entitlements": {
"GP": {
"Entitlement": "10000",
"Utilisation": "500",
"Balance": "9500"
},
"OPS": {
"Entitlement": "10000",
"Utilisation": "500",
"Balance": "9500"
},
"IP": {
"Entitlement": "10000",
"Utilisation": "500",
"Balance": "9500"
}
}