我正在尝试获取serviceResponseValue映射中“filterInputParameters”数组的值。现在我试图遍历地图,但只能获得第一级数据,例如displayName,我需要对filterInputParamters数组中的值更深一两级。如果您需要更多信息,请与我们联系。
飞镖码:
var jsonString = response;
var dropDown = querySelector("#asset");
Map jsonObject = JSON.decode(jsonString) as Map;
dropDownList = jsonObject["serviceResponseValue"] as List<Map>;
LinkedHashMap<String, Map> dataMap = new LinkedHashMap<String, Map>();
//the one causing issues and returning null
var ddValues2 = dropDownList
//extract the 'displayValue'
.map((e2) => e2['filterInputParameters']['value']);
//create a set to eliminate duplicates
//.toSet().toList()
//sort the result
//..sort();
ddValues2.forEach((e2) {
print(e2);
});
答案 0 :(得分:3)
Map jsonObject = JSON.decode(jsonString) as Map;
print(jsonObject["serviceResponseValue"][0]["filterInputParameters"]);
在JSON中[
]
表示一个列表,{
}
表示一张地图。
您可以通过传递数字索引(xxx[5]
来获取第6项)来访问列表元素
和一个用于访问Map项(xxx["serviceResponeValue"]
)的String。
您的JSON以
开头 { // the outer element is a map
"serviceResponseValue":[ // this map item can be accessed with a
// string index"serviceResponseValue"
// after the colon `:` starts the associated value, a list
// the first item can be accessed using [0]
{ // which contains a map
...
"filterInputParameters":[ // this item of the map is returned by ["filterInputParameters"]
{
"id":"8a4984e047d0e40d0147d0e410020008",