我有以下JSON字符串,它被输出:
{
"event":"build",
"tab":"map",
"selection":{
"tier":{
"id":1,
"parentId":0,
"label":"ca",
"level":100,
"hashKey":"object:5"
},
"group":{
"id":2,
"parentId":1448818,
"label":"com",
"spatialLevelId":203,
"hashKey":"object:11"
},
"area":{
"id":3,
"parentId":1449705,
"label":"cam",
"level":303,
"hashKey":"object:14"
},
"indicators":[
]
}
}
如何只从所有3个部分(层,组,区域)获取级别并将它们放入变量?
答案 0 :(得分:1)
您可以检索以下值
function handler(message) {
var tierSpatialLevelId = message.selection.tier.spatialLevelId;
var groupSpatialLevelId = message.selection.group.spatialLevelId;
var areaSpatialLevelId = message.selection.area.spatialLevelId;
}