Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a specific nested JSON property using JObject

Tags:

json

c#

json.net

How do I get a specific nested property from a JSON using JObject?

For example i want to get the uri:

{
"embed": {
    "uri": "/presets/88930"

...

like image 618
Caloyski Avatar asked Oct 22 '25 13:10

Caloyski


1 Answers

There's many ways to access the property you're interested in.

Here's one:

    String jsonData = "{ 'embed': { 'uri': '/presets/88930'}}";
    var jObject = Newtonsoft.Json.Linq.JObject.Parse(jsonData);
    Console.WriteLine((string)jObject["embed"]["uri"]);
like image 63
Socratees Samipillai Avatar answered Oct 25 '25 05:10

Socratees Samipillai