You need to sign in to do that
Don't have an account?
hiteshwar marni
json parse
How to parse this JSON
{
"results": [
{
"address_components": [
{
"long_name": "111",
"short_name": "111",
"types": [
"street_number"
]
},
{
"long_name": "Main Street",
"short_name": "Main St",
"types": [
"route"
]
},
{
"long_name": "Old East Dallas",
"short_name": "Old East Dallas",
"types": [
"neighborhood",
"political"
]
},
{
"long_name": "Dallas",
"short_name": "Dallas",
"types": [
"locality",
"political"
]
},
{
"long_name": "Dallas County",
"short_name": "Dallas County",
"types": [
"administrative_area_level_2",
"political"
]
},
{
"long_name": "Texas",
"short_name": "TX",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "United States",
"short_name": "US",
"types": [
"country",
"political"
]
},
{
"long_name": "75226",
"short_name": "75226",
"types": [
"postal_code"
]
}
],
"formatted_address": "111 Main St, Dallas, TX 75226, USA",
"geometry": {
"location": {
"lat": 32.7856754,
"lng": -96.7732783
},
"location_type": "RANGE_INTERPOLATED",
"viewport": {
"northeast": {
"lat": 32.7870243802915,
"lng": -96.77192931970849
},
"southwest": {
"lat": 32.7843264197085,
"lng": -96.77462728029151
}
}
},
"partial_match": true,
"place_id": "EiIxMTEgTWFpbiBTdCwgRGFsbGFzLCBUWCA3NTIyNiwgVVNBIhoSGAoUChIJdcuXU8CYToYRqT7JZFXIPrEQbw",
"types": [
"street_address"
]
},
{
"address_components": [
{
"long_name": "602",
"short_name": "602",
"types": [
"street_number"
]
},
{
"long_name": "Main Street",
"short_name": "Main St",
"types": [
"route"
]
},
{
"long_name": "West End",
"short_name": "West End",
"types": [
"neighborhood",
"political"
]
},
{
"long_name": "Dallas",
"short_name": "Dallas",
"types": [
"locality",
"political"
]
},
{
"long_name": "Dallas County",
"short_name": "Dallas County",
"types": [
"administrative_area_level_2",
"political"
]
},
{
"long_name": "Texas",
"short_name": "TX",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "United States",
"short_name": "US",
"types": [
"country",
"political"
]
},
{
"long_name": "75202",
"short_name": "75202",
"types": [
"postal_code"
]
}
],
"formatted_address": "602 Main St, Dallas, TX 75202, USA",
"geometry": {
"location": {
"lat": 32.7791016,
"lng": -96.8065259
},
"location_type": "RANGE_INTERPOLATED",
"viewport": {
"northeast": {
"lat": 32.78045058029149,
"lng": -96.8051769197085
},
"southwest": {
"lat": 32.7777526197085,
"lng": -96.80787488029151
}
}
},
"partial_match": true,
"place_id": "EiI2MDIgTWFpbiBTdCwgRGFsbGFzLCBUWCA3NTIwMiwgVVNBIhsSGQoUChIJ_yeoUBaZToYRaoXTXGzpnc0Q2gQ",
"types": [
"street_address"
]
}
],
"status": "OK"
}
I want to access DALLAS COUNTY
it's urgent
Thank you
{
"results": [
{
"address_components": [
{
"long_name": "111",
"short_name": "111",
"types": [
"street_number"
]
},
{
"long_name": "Main Street",
"short_name": "Main St",
"types": [
"route"
]
},
{
"long_name": "Old East Dallas",
"short_name": "Old East Dallas",
"types": [
"neighborhood",
"political"
]
},
{
"long_name": "Dallas",
"short_name": "Dallas",
"types": [
"locality",
"political"
]
},
{
"long_name": "Dallas County",
"short_name": "Dallas County",
"types": [
"administrative_area_level_2",
"political"
]
},
{
"long_name": "Texas",
"short_name": "TX",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "United States",
"short_name": "US",
"types": [
"country",
"political"
]
},
{
"long_name": "75226",
"short_name": "75226",
"types": [
"postal_code"
]
}
],
"formatted_address": "111 Main St, Dallas, TX 75226, USA",
"geometry": {
"location": {
"lat": 32.7856754,
"lng": -96.7732783
},
"location_type": "RANGE_INTERPOLATED",
"viewport": {
"northeast": {
"lat": 32.7870243802915,
"lng": -96.77192931970849
},
"southwest": {
"lat": 32.7843264197085,
"lng": -96.77462728029151
}
}
},
"partial_match": true,
"place_id": "EiIxMTEgTWFpbiBTdCwgRGFsbGFzLCBUWCA3NTIyNiwgVVNBIhoSGAoUChIJdcuXU8CYToYRqT7JZFXIPrEQbw",
"types": [
"street_address"
]
},
{
"address_components": [
{
"long_name": "602",
"short_name": "602",
"types": [
"street_number"
]
},
{
"long_name": "Main Street",
"short_name": "Main St",
"types": [
"route"
]
},
{
"long_name": "West End",
"short_name": "West End",
"types": [
"neighborhood",
"political"
]
},
{
"long_name": "Dallas",
"short_name": "Dallas",
"types": [
"locality",
"political"
]
},
{
"long_name": "Dallas County",
"short_name": "Dallas County",
"types": [
"administrative_area_level_2",
"political"
]
},
{
"long_name": "Texas",
"short_name": "TX",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "United States",
"short_name": "US",
"types": [
"country",
"political"
]
},
{
"long_name": "75202",
"short_name": "75202",
"types": [
"postal_code"
]
}
],
"formatted_address": "602 Main St, Dallas, TX 75202, USA",
"geometry": {
"location": {
"lat": 32.7791016,
"lng": -96.8065259
},
"location_type": "RANGE_INTERPOLATED",
"viewport": {
"northeast": {
"lat": 32.78045058029149,
"lng": -96.8051769197085
},
"southwest": {
"lat": 32.7777526197085,
"lng": -96.80787488029151
}
}
},
"partial_match": true,
"place_id": "EiI2MDIgTWFpbiBTdCwgRGFsbGFzLCBUWCA3NTIwMiwgVVNBIhsSGQoUChIJ_yeoUBaZToYRaoXTXGzpnc0Q2gQ",
"types": [
"street_address"
]
}
],
"status": "OK"
}
I want to access DALLAS COUNTY
it's urgent
Thank you
If you would like to parse this JSON via Apex then please go through the link https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_json_jsonparser.htm
Please mark as best answer if the above helps...!!!
Consider using JSON2Apex in the future to automatically generate the correct code from your JSON.
Here is the wrapper class for the JSON
deserialization as shown below
To parse this JSON, first paste the following code in global scope of your main class:
Now, the next step is to deserialize your response. To do that write this line in your class function where you want to deserialize this response.
string JSONResponse;//STORE YOUR RESPONSE HERE
JsonClass obj= (JsonClass) System.JSON.deserialize(JSONResponse, JsonClass.class);
Next you have to traverse the JSON object you just created using for loop.
Something Like this: