Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Json -> java object

Json -> java object

Scheduled Pinned Locked Moved Java
questionjavajsonhelptutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Evgeni57
    wrote on last edited by
    #1

    Hi There is no problem to convert JSON which looks like this: "{\"response\": {\"Code\":200, \"Text\":\"Ok\", \"Id\":\"123\"}} to the following object:

    public class JsonCL
    {
    private int Code;
    private String Text;
    private int Id;

    setters;
    getters;
    

    }

    But what about the JSON, which contains arrays of data, and nested arrays? For example: {\"response\": {\"Code\":200, \"Text\":\"Ok\", \"Id\":\"123\", \"data\":{\"groups\": [{\"key1\":\"value1\", \"nestedData\":[{\"key1\":\"value1\", \"key2\":\"value2\", \"key3\":\"value3\"},{\"key1\":\"value4\", \"key2\":\"value5\", \"key3\":\"value6\"}]},{\"key1\":\"value2\", \"nestedData\": [{\"key1\":\"value7\", \"key2\":\"value8\", \"key3\":\"value9\"},{\"key1\":\"value10\", \"key2\":\"value11\", \"key3\":\"value12\"}]}]}}} How can I convert such JSON into java object? Thanks!

    T 1 Reply Last reply
    0
    • E Evgeni57

      Hi There is no problem to convert JSON which looks like this: "{\"response\": {\"Code\":200, \"Text\":\"Ok\", \"Id\":\"123\"}} to the following object:

      public class JsonCL
      {
      private int Code;
      private String Text;
      private int Id;

      setters;
      getters;
      

      }

      But what about the JSON, which contains arrays of data, and nested arrays? For example: {\"response\": {\"Code\":200, \"Text\":\"Ok\", \"Id\":\"123\", \"data\":{\"groups\": [{\"key1\":\"value1\", \"nestedData\":[{\"key1\":\"value1\", \"key2\":\"value2\", \"key3\":\"value3\"},{\"key1\":\"value4\", \"key2\":\"value5\", \"key3\":\"value6\"}]},{\"key1\":\"value2\", \"nestedData\": [{\"key1\":\"value7\", \"key2\":\"value8\", \"key3\":\"value9\"},{\"key1\":\"value10\", \"key2\":\"value11\", \"key3\":\"value12\"}]}]}}} How can I convert such JSON into java object? Thanks!

      T Offline
      T Offline
      TorstenH
      wrote on last edited by
      #2

      check this: Json.Array @ Json.org greets Torsten

      I never finish anyth...

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups