Navigate through json objects with multiple dimensions

I am currently working on a C# project and I have encountered a scenario where I need to return a JSON object containing data from 2 different tables (Table and Table1).

My question is, how can I iterate through this data in order to copy it into 2 separate variables?

Ajax Call:-

 $(function () {
        $.ajax({
            type: 'POST',
            dataType: 'json',
            contentType: 'application/json',
            url: '@Url.Action("DrawChart")',
            data: '{}',
                success: function (chartsdataSet) {             
                    var chartsdata = chartsdataSet.Table[0];
                }
          });
      

JSON Object:-

 {
      "Table": [
        {
          "PlanName": "Half Yearly",
          "Paymentamount": 17925,
          "SettledAmount": 13300,
          "PackageAmount": 12479
        },
        {
          "PlanName": "Quaretly",
          "Paymentamount": 7900,
          "SettledAmount": 6000,
          "PackageAmount": 8000
        },
        {
          "PlanName": "Yearly",
          "Paymentamount": 8200,
          "SettledAmount": 9000,
          "PackageAmount": 5198
        }
      ],
      "Table1": [
        {
          "year": 2017,
          "monthid": 1,
          "MonthName": "Jan",
          "Paymentamount": 7900,
          "SettledAmount": 6000,
          "PackageAmount": 8000
        },
        {
          "year": 2017,
          "monthid": 2,
          "MonthName": "Feb",
          "Paymentamount": 1500,
          "SettledAmount": 1300,
          "PackageAmount": 1900
        }
      ]
    }

Answer №1

When you receive JSON data, transforming it into a Javascript object can be achieved by using JSON.parse(chartsdataSet)

 $(function() {
     $.ajax({
         type: 'POST',
         dataType: 'json',
         contentType: 'application/json',
         url: '@Url.Action("DrawChart")',
         data: '{}',
         success: function(chartsdataSet) {
             var obj = JSON.parse(chartsdataSet);
             var chartsInfo = obj.Table[0];
         }
     });
 })

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

I encountered an Unhandled Runtime Error stating that I rendered more hooks than in the previous render

I've been working on displaying my data in a table using React Table, but I keep encountering an error: Unhandled Runtime Error Error: Rendered more hooks than during the previous render. It's a new error, but at least it's progress. Thank ...

unable to establish connection due to port error in node.js

While executing node app.js I encountered the following error message info - socket.io started warn - error raised: Error: listen EACCES This snippet shows all the JavaScript code within the application. After running sudo supervisor app.js T ...

The validation feature in 1000hz Bootstrap seems to be malfunctioning

I've been working on implementing validation using the 1000hz bootstrap validation plugin. Most things are going smoothly, but I'm encountering two issues: 1). The data-match attribute doesn't seem to be working even when I enter the same p ...

"Implementing class changes based on screen size using javascript is not functioning as expected

var d = document.getElementById('promo5'); var viewportWidth = window.innerWidth; function mobileViewUpdate() { if (viewportWidth <= 700) { d.className += (" .promo5-mobile"); } else if (viewportWidth >= 700) { d ...

Svelte is unable to bring in

Hey there, I'm new to Svelte and currently working on a simple feedback app. I have divided my project into two files - one for the main app and another for a list of feedbacks. Here is my App.svelte file: <script> import feedback from ". ...

JQuery appended Bootstrap Modal to Body, but it refuses to close

After going through the process of appending the modal to the body and getting the text box working, I encountered an issue when trying to close it on the AJAX success event - none of my attempted solutions seem to be effective. var id; var refundAmount ...

Retrieve data from MongoDB using the unique identifier (_id) and additional conditions with Express

Below is the code I am currently working with: PostCategory.find({categoryid:category._id.str},function(err,postcategories){ if(err) return next(err); Post.find({_id:postcategories.postid},function(err,posts){ if(err) ...

instructions for selecting div id within the same "table td" element using jQuery

Here is the code snippet that I am working with: <td> <div id="div<%# Eval("Id") %>" class="Display"><%# Eval("Display") %></div> <div class="Actions"> </div> <div class="Comment"> <span>Comm ...

Presentation - hyperlink only functioning for final slide

I have a question about Lean Slider, which you can check out at My goal is to link each slide to a different URL. However, I'm facing an issue where only the code in the last slide seems to be executed and applied to all other slides. For example, if ...

Navigate directly to a specific slide in jQuery Cycle without using a pager manually

Is there a way to programmatically advance to a specific slide in jQuery cycle instead of relying on pager clicks? Similar to how you can advance using this syntax: $('#slideshow').cycle('next'); I am interested in passing a specific ...

Struggling to implement a sidebar in HTML using jQuery and running into issues?

I am struggling to create a template that includes a navbar, sidebar, and other elements that can be used across multiple HTML files. Despite trying different approaches, including changing the jQuery version and downloading jQuery, I am unable to make it ...

The function queryDatabases is not supported in the DocumentDB JavaScript API

Currently, I am developing a service for Azure Functions using JavaScript/Node.js. However, I encounter an error when trying to access the function DocumentClient.queryDatabases. Despite having the correct references installed in Visual Studio Code and bei ...

Extract JSON array without any accompanying objects

I am attempting to parse this JSON data, { "listname": "red", "lists": [ { "id": "01", "name": "paw", "list": [ { "id": "A", "name": "pawa", "bar": "foo" }, { "id": ...

Hover and focus effects of the main navigation menu in Semantic UI CSS

I seem to be having trouble styling my navbar with semantic-ui. I want to make changes to the color and background-color on hover and when focused. However, no matter what I try, the hover effect just won't work. I was only able to achieve it using jQ ...

Perform an Ajax call just one time

$('#addToCart').click(function () { let csrf = $("input[name=csrfmiddlewaretoken]").val(); let trTable = $(this).parents('div')[1]; let customPrice = $($(trTable).children('div') ...

How can Sequelize be used to effectively set up User Data with specific constraints?

This particular query isn't looking for the "best practice" answer, but rather a more suitable solution compared to what I currently have. Essentially, I have a User model/table that is associated with the UserScore model/table. User.belongsTo(model ...

Checking for undefined values in fields within an array of objects using scenarios in JavaScript

I am encountering an issue with checking for undefined and empty strings in an object array using Javascript. The code provided is partly functional, but I have hit a roadblock. Within the array object, If the field value is undefined or empty, it should ...

Guide on implementing the addClass method for a :before pseudo-element when clicked

A custom feature has been developed that allows for a slideDown effect when the title is clicked, revealing a new section. Initially, the title displays a plus symbol to indicate that it can be expanded. However, upon clicking the title, the intention is t ...

When retrieving a key/value pair from KAFKA with the kafka-json-schema-console-consumer tool, only the value is returned and not the key

I have been working on a Kafka source connector and have successfully published a Kafka SourceRecord with a key and its schema, along with a value and its schema. However, when I attempt to consume the message using kafka-json-schema-console-consumer on th ...

A guide on receiving object input within AngularJS

I am working on a form that looks like this: <input type="text" ng-model="gen.name" ng-repeat="gen in movie.genres"> The gen in the movie.genre is an object with two key-value pairs: Object{ id: 24, name : insidious } However, when I submit the ...