Java - extracting a value from a JSON file -


this question has answer here:

i have following json text file:

{   "quiz": {     "q1": {       "question": "is test?",       "options": [         "test a",         "test b",         "test c",         "test d"       ],       "answer": "test a"     },     "q2": {       "question": "are sure?",       "options": [         "test a",         "test b",         "test c",         "test d"       ],       "answer": "test c"     }   } } 

i trying write program able take values file , display them in gui.

at moment have following:

    jsonparser parser = new jsonparser();      try {          object obj = parser.parse(new filereader("/users/testing/desktop/workspace/test1.txt"));          jsonobject jsonobject = (jsonobject) obj;          } catch (exception e) {         e.printstacktrace();     } 

how go getting value "q1" "question"? understand in js use $.quiz.q1.question im unsure how go in java.

     jsonparser parser = new jsonparser();      try {          object obj = parser.parse(new filereader("/users/testing/desktop/workspace/test1.txt"));          jsonobject jsonobject = new jsonobject(obj.tostring);<-----change   jsonobject que1obj = jsonobject.getjsonobject("q1")<------        string questiontitle = que1obj.getstring("question");              jsonarray questionsarray =que1obj.getjsonarray("options");        string answer = que1obj.getstring("answer");           } catch (exception e) {         e.printstacktrace();     } 

Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -