arrays - How to Parse parent-child related JsonArray in JAVA? -


this json text. can "name,surname , books" array. problem books array.and content of books coming in form ;{"title:heresometext",paragraphs{value1:heresometext,value2:heresometext}} array in array. parant-child relation. thing want reach thoose value1,value2,value3 strings seperated.

{"data"   [    "name" : "here text",    "surname" : "here text",    "books" : [    {      "title1" : "here text.",      "paragraphs" : [      {          "value1" : "here text."      },      {          "value2" : "here text."      }      ]    },    {      "title2" : "here text.",      "paragraphs" : [      {          "value3" : "here text.",          "image1" : "here text."      },      {          "value4" : "here text."      },      {          "value5" : "here text."      }      ]    }    ]   ]  }

how can them form, in tree form seperated datas able save them in db. usefull

  name: "here text",    surname: "here text",    books:           - title1 : "here text."               -paragraphs:                   - value : "here text.                   - value : "here text.           - title2 : "here text."               -paragraphs:                   - value : "here text.                   - image : "here text.

we used json.simple in our projects. json parser.

example:

public class jsonparsingexample {   public static void main(string[] args) {     jsonparser parser = new jsonparser();     try {       object obj = parser.parse(new filereader(parser.getclass().getclassloader().getresource("jsondata.json").getfile()));       jsonobject jsonobject = (jsonobject) obj;       jsonobject data = (jsonobject) jsonobject.get("data");       jsonarray books = (jsonarray) data.get("books");       system.out.println(books);       iterator<jsonobject> iterator = books.iterator();       while (iterator.hasnext()) {         jsonobject book = (jsonobject) iterator.next();         system.out.println("this books name " + book.get("name"));         jsonarray paras = (jsonarray) book.get("paras");         iterator<jsonobject> parasi = paras.iterator();         int = 0;         while (parasi.hasnext()) {           jsonobject para = (jsonobject) parasi.next();           para.keyset().foreach(o -> system.out.println(o + "/" + para.get(o)));         }       }     } catch (filenotfoundexception e) {       e.printstacktrace();     } catch (ioexception e) {       e.printstacktrace();     } catch (parseexception e) {       e.printstacktrace();     }   } } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -