function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
farukh shaikhfarukh shaikh 

How to parse the below JSON response

Can someone please help me out here , I want the get the verification_status from the below response.I am not able to understand the approach.

[ { "address1":"Rua Padre Antônio D'ângelo 121", "address2":"Casa Verde", "address3":"02516-040 São Paulo SP", "components":{ "administrative_area":"SP", "dependent_locality":"Casa Verde", "country_iso_3":"BRA", "locality":"São Paulo", "postal_code":"02516-040", "postal_code_short":"02516-040", "premise":"121", "premise_number":"121", "thoroughfare":"Rua Padre Antônio D'ângelo", "thoroughfare_name":"Padre Antonio D'angelo", "thoroughfare_type":"Rua" }, "metadata":{ "latitude":-23.50948, "longitude":-46.66073, "geocode_precision":"Premise" }, "analysis":{ "verification_status":"Verified", "address_precision":"Premise" } } ]
Best Answer chosen by farukh shaikh
Sunil RathoreSunil Rathore

Hi Farukh,

It is always a good practice creating wrapper class to parse such complex JSON response. Please refer the below class which you can use in response parsing.
 

public class ParserDemo {

    public String address1;
	public String address2;
	public String address3;
	public ComponentsWrapper objComponents;
	public MetadataWrapper objMetaData;
	public AnalysisWrapper objAnalysis;

    public class ComponentsWrapper() {
		public String administrative_area;
		public String dependent_locality;
		public String country_iso_3;
		public String locality;
		public String postal_code;
		public String postal_code_short;
		public String premise;
		public String premise_number;
		public String thoroughfare;
		public String thoroughfare_name;
		public String thoroughfare_type;
	}
	
	public class MetadataWrapper() {
		public Integer latitude;
		public Integer longitude;
		public Integer geocode_precision;
	}
	public class AnalysisWrapper() {
		public String verification_status;
		public String address_precision;		
	}

 }
which you can use for deserializing as:
ParserDemo demoResponse = (ParserDemo)System.JSON.deserialize(your response, ParserDemo.class)
Now you can get verification_status as:
demoResponse.objAnalysis.verification_status
Hope this will help you. If yes, then mark it as best answer so that it can help others also.

Many Thanks,
Sunil Rathore  

All Answers

Sunil RathoreSunil Rathore

Hi Farukh,

It is always a good practice creating wrapper class to parse such complex JSON response. Please refer the below class which you can use in response parsing.
 

public class ParserDemo {

    public String address1;
	public String address2;
	public String address3;
	public ComponentsWrapper objComponents;
	public MetadataWrapper objMetaData;
	public AnalysisWrapper objAnalysis;

    public class ComponentsWrapper() {
		public String administrative_area;
		public String dependent_locality;
		public String country_iso_3;
		public String locality;
		public String postal_code;
		public String postal_code_short;
		public String premise;
		public String premise_number;
		public String thoroughfare;
		public String thoroughfare_name;
		public String thoroughfare_type;
	}
	
	public class MetadataWrapper() {
		public Integer latitude;
		public Integer longitude;
		public Integer geocode_precision;
	}
	public class AnalysisWrapper() {
		public String verification_status;
		public String address_precision;		
	}

 }
which you can use for deserializing as:
ParserDemo demoResponse = (ParserDemo)System.JSON.deserialize(your response, ParserDemo.class)
Now you can get verification_status as:
demoResponse.objAnalysis.verification_status
Hope this will help you. If yes, then mark it as best answer so that it can help others also.

Many Thanks,
Sunil Rathore  
This was selected as the best answer
farukh shaikhfarukh shaikh
Thanks Sunil It is really helpfull