我想根据条件从JSON对象获取值。
例如: 我有以下JSON对象。
{
"text": "India",
"value": 1,
"locationCode": "001",
"children": [
{
"text": "Karnataka",
"value": 37,
"locationCode": "EX01",
"disabled": "false",
"children": [
{
"text": "Hubli",
"value": 38,
"disabled": "false",
"locationCode": "UBL01",
"children": [
{
"text": "Vidyanagar",
"value": 43,
"disabled": "false",
"locationCode": "VID01",
"children": []
}
]
},
{
"text": "Bangalore",
"value": 40,
"disabled": "false",
"locationCode": "BANG01",
"children": [
{
"text": "JayNagar",
"value": 48,
"disabled": "false",
"locationCode": "JAY000",
"children": [
{
"text": "Vidyagiri",
"value": 56,
"disabled": "false",
"locationCode": "VID001",
"children": []
}
]
}
]
},
{
"text": "Mysore",
"value": 57,
"disabled": "false",
"locationCode": "CG002",
"children": []
}
]
}
]
}
我要通过此JSON传递一个位置名称,并获取父(祖父母)和孩子 (外孙)的位置。
例如:如果我通过Bangalore location,那么我应该获得以下JSON响应:
{
"text": "India",
"value": 1,
"locationCode": "001",
"children": [
{
"text": "Karnataka",
"value": 37,
"locationCode": "EX01",
"disabled": "false",
"children": [
{
"text": "Bangalore",
"value": 40,
"disabled": "false",
"locationCode": "BANG01",
"children": [
{
"text": "JayNagar",
"value": 48,
"disabled": "false",
"locationCode": "JAY000",
"children": [
{
"text": "Vidyagiri",
"value": 56,
"disabled": "false",
"locationCode": "VID001",
"children": []
}
]
}
]
}
]
}
]
}
作为回应应该给班加罗尔所在地的父母(祖父母)和孩子(孙子女)。
如何实现?
有人可以为此提供解决方案吗?