0

I have the Wrapper class, and the testwrapper class, but in my callout class i cant get it to only get out the value: 3.2

this the is api url: https://data.ssb.no/api/v0/no/table/11117

This is the json

        {
  "query": [
    {
      "code": "Leveringssektor",
      "selection": {
        "filter": "item",
        "values": [
          "B2"
        ]
      }
    },
    {
      "code": "ContentsCode",
      "selection": {
        "filter": "item",
        "values": [
          "Tolvmanedersendring"
        ]
      }
    },
    {
      "code": "Tid",
      "selection": {
        "filter": "top",
        "values": [
          "1"
        ]
      }
    }
  ],
  "response": {
    "format": "json-stat2"
  }
}

this is the response i get when i use POST function on postman, how do i deserialize the response so i can only get the value 3.2 from the response?

{
"class": "dataset",
"label": "11117: Konsumprisindeks for varer og tjenester, etter Leveringssektor, statistikkvariabel og måned",
"source": "Statistisk sentralbyrå",
"updated": "2022-06-10T06:00:00Z",
"id": [
    "Leveringssektor",
    "ContentsCode",
    "Tid"
],
"size": [
    1,
    1,
    1
],
"dimension": {
    "Leveringssektor": {
        "label": "Leveringssektor",
        "category": {
            "index": {
                "B2": 0
            },
            "label": {
                "B2": "Tjenester"
            }
        }
    },
    "ContentsCode": {
        "label": "statistikkvariabel",
        "category": {
            "index": {
                "Tolvmanedersendring": 0
            },
            "label": {
                "Tolvmanedersendring": "12-måneders endring (prosent)"
            },
            "unit": {
                "Tolvmanedersendring": {
                    "base": "prosent",
                    "decimals": 1
                }
            }
        }
    },
    "Tid": {
        "label": "måned",
        "category": {
            "index": {
                "2022M05": 0
            },
            "label": {
                "2022M05": "2022M05"
            }
        }
    }
},
"value": [
    3.2
],
"role": {
    "time": [
        "Tid"
    ],
    "metric": [
        "ContentsCode"
    ]
},
"version": "2.0",
"extension": {
    "px": {
        "infofile": "None",
        "tableid": "11117",
        "decimals": 1
    }
}

}

this is the apex code i use for deserializng, as i dont have alot of developer backend experience i dont know if this is the correct way:

public class Prosentavdeling {

public class Response {
    public String format;
}

public class Query {
    public String code;
    public Selection selection;
}

public List<Query> query;
public Response response;

public class Selection {
    public String filter;
    public List<String> values;
}


public static Prosentavdeling parse(String json) {
    return (Prosentavdeling) System.JSON.deserialize(json, Prosentavdeling.class);
}

}

1
  • 1
    Since your target value is in a JSON array (and it's contained in a JSON object), it'll be impossible to extract just your target value. At a minimum, you'd need to access that value with something like deserializedResult.value[0].
    – Derek F
    Commented Jun 12, 2022 at 12:12

1 Answer 1

0

As the Value is an array and it does not have any JSON Object you can access the value on the JSON by parsing it and get the value by checking as parsedJSON.value[0]==3.2

2
  • could you elaborate?
    – Thesulli
    Commented Jun 12, 2022 at 13:07
  • For deserializing josn you can use : link which generates JSON parser class. From the generated class you need to access the Value attribute from the class.
    – Deep
    Commented Jun 13, 2022 at 4:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .