Show the org.json.JSONArray object in a Dojo Grid

In order to retrieve data from the server, I created a servlet that adds the data to a JSONObject and sends it back to the Dojo request.get() function. While I am able to successfully receive the data, I am unsure of how to properly display the JSON content.

Below is my request.get() function:

request.get("FilenetDojoServlet", {
                sync: true,  
                timeout: 3000, 
                handleAs: "json"
                }).then(function(data){

                data4 = json.stringify(data);

                console.log("Data from server : "+data4); //displaying json string of data.
                console.log("List from data : "+data4.osList); //should display "osList" contained within data

});

After executing the code, this is the output displayed in the console:

Data from server : {"map":{"osList":{"myArrayList":["UDMS","EBILLING","BATELCO"]}}}

List from data : undefined

I am attempting to access the values within myArrayList in the JSON string. I have tried the following:

var data4 = data.map.osList.myArrayList

However, this method did not yield the expected results.

Here is the JSON data in a stringified format:

 {"map":{"osList":{"myArrayList":["UDMS","EBILLING","BATELCO"]}}}

Answer №1

To convert a JSON string into an object, you can use the JSON.parse() method. If you check the type of variable data4 using typeof, it will currently return "string", but you actually need it to be an object.

It's worth noting that Dojo has the ability to automatically decode JSON for you, which seems to have caused some confusion regarding the original question.

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

Problems encountered when trying to deploy on Firebase

I've been working on deploying my web app to Firebase, and I successfully ran the deploy script. However, when I try to access the URL, instead of seeing my app, I'm greeted with the Open Hosting Documentation page. Here is what my firebase.json ...

Guide on implementing react hook form 7 together with Material-UI switch

When utilizing react-hook-form with MUI switch, there is an issue where the initial value does not display on page load despite being set to true. However, upon form submission without any changes, the switches reflect their correct values (true or false). ...

View complex response objects in Postman as easily digestible tables

I am interested in displaying the data provided below as a table using Postman Tests. The table should have columns for product, price, and quantity, with Items listed in rows. It's important to note that there may be multiple shippingGroups within th ...

Is there a way to sort data by year and month in mongodb?

I'm trying to filter data by year in MongoDB based on a specific year and month. For example, if I pass in the year 2022, I only want to see data from that year. However, when I try using the $gte and $lte tags, it returns empty results. Can someone g ...

Updating an AngularJS directive following a service method invocation

My goal is to set up a reusable alert service that can be easily called from anywhere in my application with just: alertService.showAlert('warning', 'something went wrong!'); One example of where I want to use this is after an AJAX ca ...

Exploring Unanchored Substring Queries in Loopback API

Searching for a solution to implement a basic substring query using the loopback API for a typeahead field. Despite my efforts, I have not been able to find a clear answer. I simply want to input a substring and retrieve all brands that contain that subst ...

Do you want to reset the validation for the paper input?

I am encountering an issue with a paper-input element in my code. Here is what it looks like: <paper-input id="inputForValidation" required label="this input is manually validated" pattern="[a-zA-Z]*" error-message="letters only!"></paper-input&g ...

After executing the controller function in AngularJS, the loading icon transitions into a status icon

Is it possible to dynamically change an icon in my view based on the status of a controller function? I want the icon to initially display as a spinning wheel to indicate loading and activity while the function is executing. https://i.stack.imgur.com/I ...

Exploring the depths of Nesting in Next.js Links

After trying to nest the Badge inside the Link element and wrapping it in an <a> tag, I managed to resolve some errors but one persists: https://i.sstatic.net/o1WfA.png import { useState } from 'react'; import Link from 'next/link&apo ...

How can I change a Task into a List in this scenario?

Help needed with this issue... Encountering an error message: Unable to convert type 'System.Threading.Tasks.Task System.Collections.Generic.List Thoughts.ViewModel.PickerViewModel.Location'** to **'System.Collections.Generic.List Thought ...

The markers within a loop in react-native-maps are failing to render

Recently, I've been delving into the world of React Native app development for iOS. Specifically, I've been experimenting with the react-native-maps package. Here's the issue I'm facing: When I statically render a single MapView.Marker, ...

Guide on effectively exporting an NPM module for all browsers:

I have developed an NPM module which looks like this: class MyModule { // code here }; I am interested in making the export of MyModule universal, so that users can easily import it using any of the top 3 popular methods in the Browser: Using ES6 I ...

Changing the size of the logo as you scroll through the page

I have implemented the following code to resize the logo as I scroll down the page. $(document).on('scroll', function() { if ($(document).scrollTop() >= 10) { $('.logo img').css('width', '50px'); } else ...

Unable to extract a particular value from a JSON data structure

This situation has been on my mind for a good couple of hours now. I have this json object with example values like so: { "events": [ { "id": 64714, "live": false, "start": "1399117500", "league_ ...

Determine if the object's value is present

My current JavaScript setup looks like this: var NAMES = []; function INFO(id,first,middle,last){ var newMap = {}; newMap[id] = [first, middle, last]; return newMap ; } Next, I have the following code block: for (var j = 0; j < NUMBER.leng ...

What are the best ways to store AJAX data for future use?

$.ajax({ url:"<?php echo site_url('proposal/getContact');?>/"+client, type: 'GET', dataType: 'json', success:function(data) { //Upon success, the data is returned from the URL ...

Instructions on including a directory in the package.json file for publication on npm

I am facing an issue when attempting to publish a module in the npm repository as it is not recognizing the 'lib' folder. Even though I have included it in the package.json file as shown below, the 'lib' folder contents are not being re ...

Factory not properly updating AngularJS controller

I am facing an issue with two controllers and one factory in my AngularJS application. The first controller sends an http request to a server, receives a string in response, and stores it in the factory. However, the second controller does not update with ...

Navigating JSON data with unexpected fields in Typescript and React.js

Looking to parse a JSON string with random fields in Typescript, without prior knowledge of the field types. I want to convert the JSON string into an object with default field types, such as strings. The current parsing method is: let values = JSON.parse ...

Issue with MVC framework: AJAX query callback function not functioning properly

Struggling with implementing a basic Jquery Ajax callback: Here is my Jquery code snippet: $(document).ready(function () { $('#btnClient').click(function (e) { e.preventDefault(); var txtClient1 = $('#txtCli ...