2
{
  "albums": [
    {
      "name": "Muse",
      "permalink": "Muse",
      "cover_image_url": "http://image.kazaa.com/images/69/01672812 1569/Yaron_Herman_Trio/Muse/Yaron_Herman_Trio-Muse_1.jpg",
      "id": 93098,
      "artist_nam e": "Yaron Herman Trio"
    },

}

How do i get the value of 'name' contained in 'album'? Please help! Are there any specific ways to do it? Looked through the api and tried but stuck at retrieving the value!

0

2 Answers 2

2

Just Deserialized your json into your object.

using JsonConvert.DeserializeObject<objectType>(jsonString);

e.g; you have a class

Public class Album
{
public string name {get;set;}
public string permalink {get;set;},
public string cover_image_url {get;set;}
public int id {get;set;}
public string artist_name{get;set}
}

another class

public class Albums
{
List<Album> albums{get;set;}
}

Then just use

 var albums=JsonConvert.DeserializeObject<Albums>(jsonString);

Now albums contains the list of album objects so now you can get any value from there.

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

8 Comments

Small tip: You can use json2csharp.com to create c# classes based on a json string
what about using Jtoken under the Json.NET api?
@user1781830 If you just want to get a few items from the JSON object then you can use it
I tried JToken token = JObject.Parse(json); string album = (string)token.SelectToken("albums"); but it don't seem to be working
@user1781830 have a look here it shows how to do that stackoverflow.com/questions/4749639/…
|
0

Make sure your collection variable is declared public. For example:

public class Albums
{
   public List<Album> albums{get;set;}
}

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.