I need to parse the PRIM_CITYAC,PRIM_STATEAC,PRIM_COUNTRY_NMAC from the following response. I'm very new to REST API. I've create inner class with list in order to obtain the values. Now i got those values as expected. But I don't know how to parse the values from that.

Here is the response :

FacetCounts:[facet_fields=FacetFields:[PRIM_CITYAC=(duluth, 2, portsmouth, 2, salisbury, 2, ann arbor, 1, avon, 1, ...), PRIM_COUNTRY_NMAC=(united states (the), 7, united kingdom (the), 4, australia, 1, uk, 1, korea (the republic of), 0, ...), PRIM_STATEAC=(il, 2, mn, 2, fl, 1, ma, 1, mi, 1, ...)]]

public class MainResponseWrapper{
    public ResponseHeaderWrapper responseHeader{get;set;}
    public ResponseWrapper response {get;set;}
    public FacetCounts facet_counts {get;set;} // New stuff

public class FacetCounts {  
    public FacetFields facet_fields {get;set;}
public class FacetFields {
    public List <String> PRIM_COUNTRY_NMAC {get;set;}
    public List <String> PRIM_CITYAC {get;set;}
    public List <String> PRIM_STATEAC {get;set;}
  • Could we see the source JSON? This has got to be one of the worst JSON designs I've ever seen, if I'm reading this correctly... – sfdcfox May 18 '17 at 14:55
  • does not look like valid JSON to me – Eric May 18 '17 at 14:57
  • @Eric I said the same thing, then I realized they'd already parsed it and are debugging the results... – sfdcfox May 18 '17 at 15:02
  • A simple way to get the right classes generated (most of the time) is to paste an example of the JSON into json2apex.herokuapp.com. – Keith C May 18 '17 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.