内蒙古获取JSON数组值 [英] Obtain Inner JSON Array Values
问题描述
我试图获取值的serviceResponseValue地图内的filterInputParameters数组。现在我已试图通过地图来迭代,但只能得到如显示名数据的第一级和我需要去一两级更深在filterInputParamters数组中的值。请让我知道如果你需要更多的信息。
飞镖code:
VAR jsonString =响应; VAR下拉= querySelector(#资产); 地图的JSONObject = JSON.de code(jsonString)的地图;
DROPDOWNLIST =的JSONObject [serviceResponseValue]作为列表与LT;地图取代; LinkedHashMap的<弦乐,地图>数据映射=新的LinkedHashMap<弦乐,地图>();//在导致问题和返回null
VAR ddValues2 = DROPDOWNLIST
//提取displayValue
.MAP((E2)=> E2 ['filterInputParameters'] ['值']);
//创建一个组来消除重复
//。toSet()了ToList()
//排序结果
//..分类(); ddValues2.forEach((E2){
打印(E2); });
地图的JSONObject = JSON.de code(jsonString)的地图;
打印(JSONObject的[serviceResponseValue] [0] [filterInputParameters]);
在JSON [
]
表示列表和 {
}
的映射。结果
您可以通过传递一个数字索引访问列表元素( XXX [5]
来获得的第6项)结果
和一个String访问地图项( XXX [serviceResponeValue]
)。
您JSON与
启动 {//外部元件是一个地图
serviceResponseValue:[//此地图项目可以与访问
//字符串索引serviceResponseValue
//冒号后`:`开始关联的值,一个列表
//第一项可以用被访问[0]
{//其中包含一个地图
...
filterInputParameters://地图上的这个项目是由[filterInputParameters返回]
{
ID:8a4984e047d0e40d0147d0e410020008
I'm attempting to get the values for the "filterInputParameters" array within the serviceResponseValue map. Right now I have attempted to iterate through the map but could only obtain the first level of data such as the displayName and I need to go one-two levels deeper for the values in filterInputParamters array. Please let me know if you need more information.
Dart Code:
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);
});
Map jsonObject = JSON.decode(jsonString) as Map;
print(jsonObject["serviceResponseValue"][0]["filterInputParameters"]);
In JSON [
]
indicate a List and {
}
a Map.
You access a list element by passing a numeric index (xxx[5]
to get the 6th item)
and a String to access a Map item (xxx["serviceResponeValue"]
).
Your JSON starts with
{ // 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",
这篇关于内蒙古获取JSON数组值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!