I receive the following Json through a web service:
{ report: { Id: "aaakkj98898983" } }
I want to get value of the Id. How to do this in C#? THANKS
The website states the following: Jansson is a C library for encoding, decoding and manipulating JSON data. It features: Simple and intuitive API and data model. Can both encode to and decode from JSON.
To access the JSON object in JavaScript, parse it with JSON. parse() , and access it via “.” or “[]”.
First, download Newtonsoft's Json Library, then parse the json using JObject. This allows you to access the properties within pretty easily, like so:
using System; using Newtonsoft.Json.Linq; namespace testClient { class Program { static void Main() { var myJsonString = "{report: {Id: \"aaakkj98898983\"}}"; var jo = JObject.Parse(myJsonString); var id = jo["report"]["Id"].ToString(); Console.WriteLine(id); Console.Read(); } } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With