0

I have REST webservice which gives response in Json format, I have locally assigned the Json response in a variable. But now I want to know if we can parse and how. Below is a response from webservice.

{
  "actionresult": "successful",
  "licenceDetail": [
    {
      "licence": "SA123",
      "type": "SZ Abalone",
      "pendingtrip": [

      ],
      "Vessel": [
        {
          "name": "Red Fire",
          "number": "SA123"
        }
      ],
      "defaultvalue": {
        "LandingPort": "Anxious Bay",
        "DepartPort": "Acramans Creek",
        "Vessel": "SA123",
        "AreaFishing": "SA"
      }
    },
    {
      "licence": "K01",
      "type": "Blue Crab",
      "pendingtrip": [

      ],
      "Vessel": [
        {
          "name": "Abrolhos Spirit",
          "number": "K01"
        }
      ],
      "defaultvalue": null
    }
  ]
}

Any help will be appreciated. Regards, Rohit

Raju
  • 2,902
  • 8
  • 34
  • 57
rohit dhar
  • 1
  • 1
  • 1
  • 2
    This question is effectively a duplicate of this: http://stackoverflow.com/questions/2591098/how-to-parse-json-in-java – Tibrogargan Mar 11 '16 at 05:35

3 Answers3

0

use Jackson2 library for converting json string into Object class.

0

I always use Gson. This is very easy to use.

Gson gson = new GsonBuilder().create();
MyClass myClass = gson.fromJson(jsonString, MyClass.class);

Maven dependency

    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.4</version>
    </dependency>
Lenar
  • 419
  • 4
  • 19
0

here you can read it in detail ObjectJson

   JsonReader rdr = Json.createReader(is)) {

 JsonObject obj = rdr.readObject();
  JsonArray results = obj.getJsonArray("licenceDetail");
 for (JsonObject result : results.getValuesAs(JsonObject.class)) {
 String Landing   result.getJsonObject("Default Value").getString("Landing port");

 }
Shubham
  • 189
  • 9