Seeking a way to access Json parse with special characters?

I'm facing a challenge with the JSON output below, specifically when dealing with certain characters.

JSON String

{
    "results": {
        "RESULT1-Node1": {
            "Network.MS": "405",
            "Down_time": "131"

        },
        "RESULT4-Node2": {           
            "Network.MS": "451",
            "Down_time": "141"                         }
             }
}

Javascript

     for (var resultBank in jsonData.results) {
            var rootType = resultBank ;
            console.log(rootType );
             for(var result in eval("resultBank."+JSON.stringify(rootType)) ){

                console.log(result[result]); 

             }  
}

Answer №1

When utilizing the for (var x in y) loop to iterate through the contents of y, the x variable is assigned the index of each element. Therefore, to access the actual item itself, you would use y[x].

for (var dataEntry in jsonData.results) {
    var dataType = dataEntry ;
    console.log(dataType );
    for(var resultItem in jsonData.results[dataEntry]) {

        console.log(jsonData.results[dataEntry][resultItem]); 

    }  
}

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

How can I prevent the arrow keys and space bar from causing my webpage to shift downwards?

I created a game where the arrow keys control movement and the space bar shoots, but every time I press the down key or space bar, it scrolls to the bottom of the web page. Is there a way to adjust the CSS so that it focuses on the game div tag without ...

When utilizing a Service through UserManager, the User variable may become null

Utilizing Angular 7 along with the OIDC-Client library, I have constructed an AuthService that provides access to several UserManager methods. Interestingly, when I trigger the signInRedirectCallback function from the AuthService, the user object appears ...

What is the most efficient way to handle dependencies and instantiate objects just once in JavaScript?

I am interested in discovering reliable and tested design patterns in Javascript that ensure the loading of dependencies only once, as well as instantiating an object only once within the DOM. Specifically, I have the following scenario: // Block A in th ...

Encountering an issue with an Angular application: TypeError occurs when attempting to read property 'then' of undefined

I encountered an error while performing a post from my controller. function postDashboardsData (dataType, dateFrom, dateTo) { $scope[dataType + '_done'] = false; Api.post('rotations/' + vm.data[0]._id + '/dashboard&apo ...

Incorporating an external HTML page's <title> tag into a different HTML page using jQuery

I am faced with a challenge involving two files: index.html and index2.html. Both of these files reside in the same directory on a local machine, without access to PHP or other server-side languages. My goal is to extract the <title>Page Title</ ...

The expected result is not obtained when making an Ajax request to a PHP variable

I recently encountered an issue with my AJAX GET request. The response I received was unexpected as the PHP variable appeared to be empty. Here is the snippet of jQuery code that I used: jQuery(document).ready(function($) { $.ajax({ url: '/wp ...

"I need assistance with parsing a multi-level JSON array using ServiceStack.Text library. Can someone guide me on

After reading through this article, I'm encountering some difficulties implementing it in my specific scenario. Here is the Google Maps JSON string format that I am working with (utilizing the structure from Blitzmap.js): { "zoom":12, "overlay ...

Extracting information from an ENORMOUS Array

Let's start with my code snippet, featuring an array: var UserProfiles = [{ userProfileID: 1, firstName: 'Austin', lastName: 'Hunter', email: 'test', token: '', platform: 'android ...

Fill the table with information from two different datasets and input the data into the same cell

I have an issue with populating a table using two data sets. So far, I am able to populate the table from the first data set. However, I do not want to simply append the second data set (data2). Instead, I want to add the data in the same td's below ...

Navigating through the various child objects within a JSON structure

As I traverse through a moderately complex JSON object, I gather and store all the values once I reach the end of the recursive loop Here is an example of the object: "if": { "and": { "or": { "compare": [ { ...

How to dynamically modify ion-list elements with Ionic on button click

Imagine having 3 different lists: List 1: bus, plane List 2: [related to bus] slow, can't fly List 3: [related to plane] fast, can fly In my Ionic Angular project, I have successfully implemented the first ion-list. How can I dynamically change th ...

Using JQuery to target and style individual td elements within a database in a

Hey there! I'm currently in the process of learning jQuery and I've encountered a little issue with the code below: <table class="table table-bordered table-striped table-hover datatable"> <thead> <tr> & ...

Using Ajax to send data from a parent JSP to a child JSP and then refresh the page

Can anyone assist me in resolving my issue? I'm attempting to incorporate an existing JSP partial (child) into another JSP page (parent). These pages are controlled by Java Controller classes in a Weblogic 12c environment using Spring. The child JSP i ...

Python code encounters a JSONDecodeError while extracting information from a URL

I'm currently attempting to retrieve transaction data for a specific set of addresses: wallet_addresses = ['0x7abe0ce388281d2acf297cb089caef3819b13448', '0xC098B2a3Aa256D2140208C3de6543aAEf5cd3A94', '0x2FAF487A ...

What is causing the error that app.js file cannot be located?

Here is the layout of my directory: ReactCourse // Main folder public // Subfolder within ReactCourse index.html // HTML file with linked js file app.js // JavaScript file This is the content of index.html: <!DOCTYPE ...

The scroll feature is not functioning properly in detecting the CSS function for the final div

$(document).ready(function() { $(document).on("scroll", onScroll); //smoothscroll $('a[href^="#"]').on('click', function(e) { e.preventDefault(); $(document).off("scroll"); $('a').each(func ...

Failure to display masonry arrangement

I am working on creating a stunning masonry layout for my webpage using some beautiful images. Take a look at the code snippet below: CSS <style> .masonryImage{float:left;} </style> JavaScript <script src="ht ...

JSON organized in a hierarchical manner with a tree-like structure

I'm working on creating a tree-like JSON structure in Java where there is a parent node with multiple children nodes. While I have made progress on the code, it's not completely successful yet. Here is the desired output: { "name": "Culture" ...

The Facebook JavaScript API function FB.api() is limited to posting messages and does not support media attachments

I am attempting to share a message with an mp3 attachment on the active user's wall. It works perfectly fine within Facebook's Test Console, but when I try it from my mobile app, only the message gets posted. Can anyone help me figure out what I ...

Vue.js view fails to refresh upon receiving an event through eventbus

Just diving into Vue.js 2 and working on my very first (vue) web application. The setup includes two components - a header component and a login component. Once the login process is successful, a "loggedIn" flag gets toggled within an authentication servic ...