I am interested in extracting specific data from the JSON response

I am trying to extract the value of the message parameter under the messages array where the parameter name is equal to documentId (highlighted in bold below). However, the code I have tried so far does not achieve this as needed.

dynamic obj = JsonConvert.DeserializeObject(JsonDATA);
var recid = obj.messages.message;

JSON Data

{
  "message": "Success",
  "messages": [
    {
      "parameter": "documentId",
      "message": "8111ffb4-dddc-4d94-b050-bf8fa050181f"
    },
    {
      "parameter": "refNo",
      "message": "INNT19/75254854"
    }
  ]
}

I need assistance on how to specifically retrieve only the desired value in C#.

Answer №1

It is essential to retrieve the message from the messages-array by using the correct index:

dynamic object = JsonConvert.DeserializeObject(JsonDATA);
var messageId = object.messages[0].message;

Answer №2

When working with an array like messages in your JSON data, remember that you can access specific properties by using the corresponding index. For example:

var messageId = obj.messages[0].message;

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

Benefits of utilizing minified AngularJS versions (Exploring the advantages of angular.min.js over angular.js, along with the inclusion of angular.min.js.map)

After introducing angular.min.js into my project, I encountered a problem. http://localhost:8000/AngularProject/angular.min.js.map 404 (Not Found) angular.min.js.map:1 Upon further investigation, I discovered that including angular.min.js.map resolve ...

React application triggers `OnKeyDown` event just once

Hey there! I'm diving into the world of web development and could use some help. My current challenge involves manipulating input data based on key combinations like ctr + ArrowUp (increase) and ctr + ArrowDown (decrease). The dynamic part should be h ...

Error encountered in Vue.js: Unexpected "<" symbol found at the beginning of JSON data retrieved from an express server

Below you will find my Vue.js code: const load = async () => { try { // let data = await fetch(`127.0.0.1:4433/users/`, { // // method: "GET", // // headers: { "Content-t ...

Trigger SocketIO message when the page is closed or when the user confirms leaving the page with on

My server application is responsible for executing firmware updates on remote devices using radio communication. Occasionally, the update process may drag on indefinitely due to disruptions in the radio network. If this happens, users might want to interr ...

Enhancing user experience with VideoJS player overlay buttons on mobile devices

I am currently using VideoJs player version 4.2. When I launch a videojs player on Safari browser in an iOS device, it defaults to native controls. However, when I pause the player, overlay buttons (links to navigate to other pages) are displayed on the v ...

Icon not displaying in Firebase background service worker notifications with JavaScript

Although my firebase-messaging-sw.js is functioning properly in displaying background notifications, I have encountered an issue where the icon does not show up even though notification.title and notification.click_action are working correctly. Here is th ...

Exploring the capabilities of SwiftUI to create custom nested array structures using For

Recently, I've encountered a challenge with a nested array of a particular model: let models = [[ButtonModel]] struct ButtonModel: Identifiable { let id = UUID() let value: String let style: ColorStyle init ...

Check out the JSON feed in Swift 3.0

I'm attempting to display my PHP result in an iOS app using the following code: func get() { //let url = NSURL(string: "http://www.w3schools.com/js/customers_mysql.php") let url = NSURL(string: "http://www.helpmewastetime.com/ser ...

How can you refresh the information shown in a separate component from the search input with a live search bar?

Currently, I am working on integrating a live search functionality into my Next.js application. While I have successfully managed to capture input changes, I am facing difficulties in filtering the results based on the user input. Here is a snippet of the ...

Make your CSS and JS files smaller by using a PHP compression script in your WordPress child theme

  I am looking to implement a PHP script that will serve combined, pre-gzipped, and minified JS and CSS files. You can find the source code for this script here: https://code.google.com/p/compress/ I have a WAMP localhost with WordPress install ...

Encountering a 404 error in Codeigniter when making an AJAX call

After successfully implementing an upload form with ajax, I encountered some issues when attempting to delete uploaded photos. Initially, I received a "csrf protection error," which led me to disable csrf protection, only to then encounter a "404 not found ...

Asynchronously retrieving results in MongoDB

My task involves fetching all users from the users collection. app.post('/login', function(req,res,next){ users = self._db.get('users', {}) }) Below is the function in my database class: this.get = function( col, opt ) { ...

Should I convert to an image or utilize the canvas?

I'm debating whether it's more efficient to convert a canvas drawing into an image before inserting it into the DOM, or if it's better to simply add the canvas itself. My method involves utilizing canvas to generate the image. ...

Parsing string to JSON object and extracting specific information

In my code, I have a variable named "response" that contains the following string: {"test": { "id": 179512, "name": "Test", "IconId": 606, "revisionDate": 139844341200, "Level": 20 }} My goal is to extract the value of the id key and store ...

Issues with AJAX junk appearing after the document element in Firefox are causing disruption

Currently, I am utilizing a page fetch script to dynamically insert a web page into a div element on my site. Let's take a look at the code. By the way, I am running this on Firefox with Kubuntu. function fetchContent(URL, divId) { req = wind ...

Troubleshooting RXjs problems on Heroku deployment

I've encountered an issue with my NodeJS/Angular2 website. It functions smoothly on my local Windows 10 setup, but when I attempt to deploy it on Heroku and access the site, the front-end console in Chrome displays an error message and the site fails ...

Is there a way for me to calculate the square of a number generated by a function?

Just starting out with Javascript and coding, I'm having trouble squaring a number that comes from a function. I've outlined below what I am trying to achieve. Thank you in advance for your help. // CONVERT BINARY TO DECIMAL // (100110)2 > ( ...

Reducing an array group using index in JavaScript: A beginner's guide

Do you have coding questions? Check out this sample array group: myArray = { tab1 : [], tab2 : [], tab3 : [], tab4 : [] } I'm looking to always retain the first tab (tab1) and an additional tab based on an index (ranging from 2 to 4) For instance, ...

Issue with retrieving data using AngularJS Restangular

I've been trying to figure out how to make restangular work properly. When I call my API (using the endpoint /user) I receive the following JSON response: { "error": false, "response": { "totalcount": 2, "records": [{ "id": "1", ...

Error encountered with AJAX call when attempting to utilize string method

I am looking to add HTML content to a TinyMCE editor in an ASP.NET MVC project. After some thought, I have found a solution that involves converting the HTML file to a string on the server side and then calling it using Ajax on the client side. Here is a ...