Exploring the Android JSON object

After downloading a JSON file, I found the following structure:

    {
        "options": {
        "toolbar": "1",
        "full": "1",
        "exit": "0",
        "about": "0"
    },
   "general": {
     "versioncontrol": "1.0"
   },
  "companydetails": {
    "toolbaricons": {
      "1": [
        "Facebook",
        "xxx",
        "xxx"
      ],
      "2": [
        "Instagram",
        "xxx",
        "xxx"
      ],
      "3": [
        "LinkedIn",
        "xxx",
        "xxx"
      ]
    },
    "buttons": "4",
    "openingtimes": {
      "1": "10:00 - 16:00",
      "2": "9:00 - 16:00"
    }
  }
}

After retrieving it as a string from the server and storing it in a variable, I tried to parse the data using the following code:

JSONObject jsonObj = new JSONObject(fileOutput);
JSONArray details = jsonObj.getJSONArray("options");
JSONObject c = details.getJSONObject(0);

However, I am having trouble extracting information from it. My goal is to access different elements within 'options' and gather the necessary information. Despite attempting to log the details of 'options', I haven't been able to make it work. Previously, my method was functional but due to changes in the file structure, it no longer functions correctly.

Answer №1

When working with JSON data, remember that options is an object and not an array. You can access it using:

JSONObject jsonObj = new JSONObject(fileOutput);
JSONObject options = jsonObj.getJSONObject("options");
int toolbar = options.getInt("toolbar");

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Restoring a file from archive in Amazon Web Services S3

As I work on a project, my current task involves uploading a collection of JSON files to Amazon S3 for mobile clients to access. To potentially lower the expenses related to individual file transfers, I am pondering whether it is achievable to unzip a fil ...

AngularJS utilizes a nested ng-repeat for displaying folder structures in the user interface

I am facing a challenge where I need to generate a comprehensive list of files and folders from a JSON object. The folder structure can be quite intricate, with the potential for multiple nested levels. In my specific example, I have only included up to th ...

The functionality of my website is not optimized for viewing on iPhones

While designing a responsive website that looks great on most devices, I noticed some issues with iPhones. The layout breaks in two specific ways on these devices. View Galaxy Screenshot View Sony Screenshot The menu doesn't scale properly on iPho ...

Having difficulty accessing span class and data

Having trouble getting text from a specific span class. <span class="one"> First Text </span> <span class="two"> Second Text </span> Attempting to locate it using JAVA code WebElement element = driver.findElement(By.className("o ...

What is the best way to return JSON from a 403 error using Express?

Express has the ability to handle errors, and you can send back JSON data when returning a 403 status code like this: let error = {errorCode:"1234"} res.sendStatus(403, {error: error}); To catch and inspect the error in your frontend JavaScript, you can ...

Alerts created with the AlertController in Ionic 4 Angular are not displaying the message when the

After creating a reliable alert service for my Ionic 4 project, I encountered an issue when building the release version of the app. Despite functioning perfectly in other environments like "ionic serve" and "ionic cordova emulate", the message part of the ...

Tips for deserializing JSON data in NewtonSoft into static classes with nested structures

One scenario involves a nested class with static properties, as demonstrated below: public class X { public class Y { public static string YString = null; } } Consider the following JSON data: { Y { "YString" : "World" } ...

What could be causing the alteration of my JSON data when sent through a WEB.API Ajax request?

Before Ajax Call: "{ "UnitOfMeasureRelatedUnitDataInbound": [ { "Name": "test", "Active": true, "UnitOfMeasureTypeID": "dd89f0a0-59c3-49a1-a2ae-7e763da32065", "BaseUnitID": "4c835ebb-60f2-435f-a5f4-8dc311fbbca0", "BaseUnitName": null, ...

Utilize jQuery to extract data from a JSON object

While I have come across numerous examples of parsing JSON objects in jQuery using $.parseJSON and have grasped the concept, there are some fundamental aspects missing that are preventing me from successfully parsing the following VALID JSON: { "studen ...

Receiving response in JSON format from a web service

I have been attempting to retrieve a JSON response from a web service, but the response I am receiving contains XML. It looks like this: <?xml version="1.0" encoding="utf-8"?> <string xmlns="http://tempuri.org/">[["123","testing123"]]</stri ...

Learn how to automatically fill prototype cell text labels with NSDictionary data pulled from JSON through AFNetworking

Recently delving into iOS development, I have been working on downloading JSON data using AFNetworking and storing it in a Dictionary object. Check out the code snippet below to see how this is accomplished: -(void)locationRequest { NSURL *url = [NSURL U ...

Retrieving data from a JSON object in Python

I have a python script that handles http post requests from an application that sends the payload as JSON. class S(BaseHTTPRequestHandler): def _set_response(self): self.send_response(200) self.send_header('Content-type', &ap ...

Validation of JSON Failed

Encountered a 400 Bad Request error while attempting to POST an answer using Postman, it appears to be a validator issue. Despite multiple attempts, I have yet to resolve this issue. Below are details of the JSON data being sent in the POST request along w ...

Issue encountered with geckodriver: Unexpected argument '--websocket-port' was detected

I recently updated my Selenium project using the Bonigarcia autodownload webdriver project to the latest versions. I upgraded to Selenium 4.0.0 from Maven repo and also updated the Bonigarcia project to version 5.0.3. However, now when I try to run my test ...

tips for navigating through an AngularJS $resource instance

I am facing a frustrating issue that I need assistance with. The problem arises when I try to extract specific data from each element of the stock data fetched by my controller from Yahoo Stocks. Although the data is stored in $scope.stocks and can be disp ...

Experiencing a Type Mismatch Error while extracting Summary data

I'm currently developing a Recipe App, and I've successfully managed to parse the JSON data. However, I've hit a roadblock when it comes to implementing a specific section of each recipe: recipe.json Here is an example snippet from a Recip ...

Obtain some content using Java along with Selenium WebDriver

I only want to extract the text "Invitation sent to xxxxx". I do not need the content inside the button tag. <button class="action" data-ember-action="" data-ember-action-3995="3995"> Visualizar profile </button> This is how I am c ...

Using Custom GeoJSON Data with HighMaps Tutorial

Currently, I have created a custom .geo.json file from a county shapefile using ogr2ogr. My goal is to manually add values for each county. After studying a jsfiddle example (link provided), I'm unsure how to merge the two together. The specific line ...

The Selenium webdriver successfully refocusing on the parent window after dealing with a pop-up child window

I am facing an issue while trying to switch from a pop-up window back to the parent window that was generated by a click event. Various methods were attempted, but none of them proved successful in resolving the problem. public static String verifyHierar ...

Is it possible to search and index nested object keys in JSON using PostgreSQL?

If my database table 'configurations' contains rows with a 'data' column in JSONB format like the example below: { "US": { "1234": { "id": "ABCD" } }, " ...