1

Here is the JSON that needed to be proper parsed:

https://docs.acrcloud.com/metadata

i am trying to get the:

title of the song, album name, artists.

I tried like this:

 JObject o = JObject.Parse(result);            
 Console.WriteLine("Name: " + o["metadata"]["music"]);

and it works but i am getting all the data in "music" i just need to extract the specific data.

3
  • Then take your "specific data" instead! Commented Sep 5, 2015 at 23:19
  • i don't know how @cubrr check the JSON it is little bit complicated Commented Sep 5, 2015 at 23:20
  • 1
    Well, you've already got "music" from the "metadata". Now repeat the process to get "title" from "music". It looks like the object is inside an array though so o["metadata"]["music"][0] will get you access to the actual object. Commented Sep 5, 2015 at 23:25

1 Answer 1

1

You can use SelectTokens and SelectToken for this purpose. They both support JsonPATH query syntax including wildcards:

        var o = JToken.Parse(result);
        var musicInfo = o.SelectTokens("metadata.music[0]")
            .Select(t => new
            {
                SongTitle = (string)t.SelectToken("title"),
                AlbumName = (string)t.SelectToken("album.name"),
                Artists = t.SelectTokens("artists[*].name").Select(n => (string)n).ToArray()
            })
            .FirstOrDefault();

Then

        Console.WriteLine(JsonConvert.SerializeObject(musicInfo, Formatting.Indented));

Prints

{
  "SongTitle": "Listen (From the Motion Picture \"Dreamgirls\")",
  "AlbumName": "B'Day Deluxe Edition",
  "Artists": [
    "Beyoncé"
  ]
}

which is what you want.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.