0

i have problem with get specified value from json. I need get Key value from json below, its start with array/list.

[
  {
    "Version": 1,
    "Key": "353333_PC",
    "Type": "PostalCode",
    "Rank": 500,
    "LocalizedName": "Suwalki",
    "EnglishName": "Suwalki",
    "PrimaryPostalCode": "16-400",
    "Region": {
      "ID": "EUR",
      "LocalizedName": "Europe",
      "EnglishName": "Europe"
    },
    "Country": {
      "ID": "PL",
      "LocalizedName": "Poland",
      "EnglishName": "Poland"
    }
  }
]

I have tried code like this:

        String content = parent.path("Key").asText();
        return content;

but it returns empty string. Have u any idea how get this?

  • Please post other parts of your code. – soumya-kole Sep 30 '20 at 10:15
  • 2
    You will find a solution here: https://stackoverflow.com/questions/2591098/how-to-parse-json-in-java Hope it will help! – n2ad Sep 30 '20 at 10:19
  • The most simple way is using JSONNode. You can create the JSONNode from JSON string using com.fasterxml.jackson.databind.ObjectMapper. Then use findValue("key name") method to get the value from JOSNNode like jsonNode.findValue("key"). If it is a array iterate the JSONNode and get the value from the child node – Sangeetharaj Oct 05 '20 at 05:58

0 Answers0