json type :1
var x={
"address": {
"county": "abc",
"state_district": "asd",
"state": "test",
"country": "test1",
"country_code": "test"
}
}
Type:2
var x ={ "address": {
"suburb": "",
"city_district": "",
"city": "",
"county": "",
"state": "",
"postcode": "",
"country": "",
}}
type:3
var x= {"address": {
"amenity": "",
"road": "",
"town": "",
"county": "",
"state_district": "",
"state": "",
"postcode": "",
"country": "",
"country_code": ""
}
}
switch(x.address)
{
case 'city':
return x.address.city;
break;
case 'village':
return x.address.village;
break;
default:
alert('err');}
This my JSON content. address
property will have some additional key values depending on locality like city
, village
, suburb
, etc.
I need to check if a particular key is present or not using switch statement. Sample JSON with additional property are shown above.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…