Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8262747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:51:34+00:00 2026-06-08T03:51:34+00:00

I am getting a JSON response back from a server and the array I

  • 0

I am getting a JSON response back from a server and the array I need to grab is a value embedded deep inside multiple objects and arrays. I need to grab the formatIds JSONArray. My JSON looks like this:

{
    "entries": [
        {
            "title": "sample",
            "targets": [
                {
                    "format": "wav",`enter code here`
                    "description": "A wav file",
                    "formatCriteria": [
                        {
                            "formatSelectionTitle": "Find WAV files",
                            "formatSteps": {
                                "UniqueId": "214212312321",
                                "formatMatches": {
                                    "formatIds": [
                                        "WAV",
                                        "MP3"
                                    ]
                                }
                            }
                        }
                    ]
                }
            ]
        }
    ]
}

The only way I have been able to figure out is to have a bunch of embedded for loops:

String[] assetUri;
for (int i = 0; i < entriesArray.length(); i++) {
    entryJsonOjbect = entriesArray.getJSONObject(i);
    fileTargetArray = tempObj.getJSONArray("targets");
    //Loop through the targets array
    for (int j = 0; j < fileTargetArray.length(); j++) {
        tempObj = fileTargetArray.getJSONObject(j);
        fileCriteriaArray = tempObj.getJSONArray("formatCriteria");
        //Loop through fileCriteria Array
        for (int h = 0; h < fileCriteriaArray.length(); h++) {
            JSONObject fileCriteriaObj = fileCriteriaArray.getJSONObject(h);
            //Get the JSON Object 'formatSteps'
            JSONObject selectStepObj = fileCriteriaObj.getJSONObject("formatSteps");
            //Get the JSON Object 'formatMatches'
            JSONObject selectionMatches = selectStepObj.getJSONObject("formatMatches");
            //FINALLY. Get the formatIds ARray
            JSONArray assetTypeArray = selectionMatches.getJSONArray("formatIds");
                //Assign the values from the JSONArray to my class
                assetUri = new String[assetTypeArray.length()];
                for (int z = 0; z < assetTypeArray.length(); z++) {
                    assetUri[z] = assetTypeArray.getString(z);
            }

        }
    }
}

This code REALLY REALLY slow x20 because of all the embedded loops. Is there a way for me to get this JSONArray without having to have this extra code?? In jQuery there is a JSON.find and was wondering if there something similar to this in Java? I have tried the JSON API calls getJSONArray and get on the root jsonObject but it doesn’t work unless you are in object in which the json array exists. I’m sure I could do some type of recursive solution but this is still annoying. Any advice??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T03:51:35+00:00Added an answer on June 8, 2026 at 3:51 am

    Parsing JSON with the org.json-library is like parsing XML with DOM: Step by step. But: You’ll need all these loops.

    If your JSON response always looks like the one you posted (a single element in every array), your JSON is very ineffective. If you just want the “first” entries, don’t loop over the arrays.

    Parsing such a complex data-structure with org.json can be a pain. Have you tried the (more automated) google-gson library? Check out the examples. Although I don’t want to say that parsing it with gson will be faster in terms of CPU time, it will deficiently be faster in terms of development time.

    I also just recently wrote a blog-post about this topic: JSON and Java

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting JSON response from the server..Inside that JSON string i am having
I am getting json data as a response back from the server. I want
I am getting a JSON in response from server: { width: 765, height: 990,
I have an array of 'tasks' that I am getting back from a JSON
I'm getting the following (str) back from Disqus, JSON expected: ?({code: 0, response: {username:
I am getting json response from this google api service to get reverse geo
I'm having trouble getting a response from my php jquery / json / ajax.
Getting Json from the Server and displaying it in the grid is relatively straight
I am getting a response back from a Google Search Appliance suggest service in
I'm having trouble getting a response back from a Jquery ajax call... (It's a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.