Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Parsing an Array of Arrays with Gson

  1. #1
    Junior Member
    Join Date
    Jan 2021
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Parsing an Array of Arrays with Gson

    So im working on this program. I have this JSON:

    {"applications":
    ------[{"id":13594,"answers":
    ----------[{"id":352,"question":"Where are you planning to build in The Midwest? [Illinois, Nebraska, Etc]","answer":"Kansas"},
    -----------{"id":599,"question":"How old are you?","answer":"18"},
    -----------{"id":683,"question":"Link an image of the IRL building here if it is not included with your build. Please submit completed builds, all applications with uncompleted builds will be
    ------------rejected. You can always reapply once it is completed.","answer":"The irl builds are in the gallery"},
    -----------{"id":691,"question":"Do you understand that if you submit build/s that are not yours, this application will be rejected and all future applications to this team will also be
    ------------rejected?","answer":"Yes, I understand"},
    -----------{"id":696,"question":"What is your minecraft username?","answer":"Mudkip557"}],"mediaUrl":"https://imgur.com/gallery/TA2jZNm"}]}

    So doing "jsonarray = someJsonElement.getAsJsonObject().getAsJsonArray(" applications");" will return the "applications" array but what I want is the "answers" array (which only includes all the questions). How would i do this with Gson? (im sorry i dont know how to format this JSON so it will look nice but i tried)
    Last edited by cuzzo; January 24th, 2021 at 01:53 PM.

  2. #2
    Junior Member
    Join Date
    Jan 2021
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Parsing an Array of Arrays with Gson

    So im working on this program. I have this JSON:

    {"applications": [
              {
                     "id":13594,
                     "answers": [
                        {
                             "id":352,
                             "question":"Where are you planning to build in The Midwest? [Illinois, Nebraska, Etc]",
                             "answer":"Kansas"
                        },
                        {
                             "id":599,
                             "question":"How old are you?",
                             "answer":"18"
                         },
                         {
                             "id":683,
                             "question":"Link an image of the IRL building here if it is not included with your build. Please submit completed builds, all applications with uncompleted builds will be
                              rejected. You can always reapply once it is completed.",
                             "answer":"The irl builds are in the gallery"
                         },
                         {
                             "id":691,
                             "question":"Do you understand that if you submit build/s that are not yours, this application will be rejected and all future applications to this team will also be
                              rejected?",
                             "answer":"Yes, I understand"
                         },
                         {
                             "id":696,
                             "question":"What is your minecraft username?",
                             "answer":"Mudkip557"
                          }
                    ],
                   "mediaUrl":"https://imgur.com/gallery/TA2jZNm"}]}

    So doing "jsonarray = someJsonElement.getAsJsonObject().getAsJsonArray(" applications");" will return the "applications" array but what I want is the "answers" array for the first element in the "applications" array (which only includes all the questions and answers). How would i do this with Gson?
    Last edited by cuzzo; January 24th, 2021 at 02:12 PM. Reason: code format

Similar Threads

  1. Manipulating array of arrays...
    By choloboy in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 1st, 2013, 02:19 PM
  2. Struggling with an Array of Arrays
    By bhenry1790 in forum Loops & Control Statements
    Replies: 6
    Last Post: July 23rd, 2012, 09:38 AM
  3. [SOLVED] Filling a 2D array with other arrays.
    By mwebb in forum Object Oriented Programming
    Replies: 4
    Last Post: March 1st, 2012, 05:11 PM
  4. Arrays and array list
    By rob17 in forum Collections and Generics
    Replies: 2
    Last Post: February 19th, 2012, 06:10 PM
  5. Gson Formatting
    By techwiz24 in forum Java Theory & Questions
    Replies: 4
    Last Post: October 2nd, 2011, 07:48 PM

Tags for this Thread