I am attempting to map a JSON string being returned to me into a .Net model class that I have. The JSON is going to be an array of any number of results, and I would like to return a List<MyObject>
from this method.
The JSON looks like this:
{
"artists" : {
"href" : "https://api.spotify.com/v1/search?query=tania+bowra&offset=0&limit=20&type=artist",
"items" : [ {
"external_urls" : {
"spotify" : "https://open.spotify.com/artist/08td7MxkoHQkXnWAYD8d6Q"
},
"followers" : {
"href" : null,
"total" : 26
},
"genres" : [ ],
"href" : "https://api.spotify.com/v1/artists/08td7MxkoHQkXnWAYD8d6Q",
"id" : "08td7MxkoHQkXnWAYD8d6Q",
"images" : [ {
"height" : 640,
"url" : "https://i.scdn.co/image/f2798ddab0c7b76dc2d270b65c4f67ddef7f6718",
"width" : 640
}, {
"height" : 300,
"url" : "https://i.scdn.co/image/b414091165ea0f4172089c2fc67bb35aa37cfc55",
"width" : 300
}, {
"height" : 64,
"url" : "https://i.scdn.co/image/8522fc78be4bf4e83fea8e67bb742e7d3dfe21b4",
"width" : 64
} ],
"name" : "Tania Bowra",
"popularity" : 2,
"type" : "artist",
"uri" : "spotify:artist:08td7MxkoHQkXnWAYD8d6Q"
} ],
"limit" : 20,
"next" : null,
"offset" : 0,
"previous" : null,
"total" : 1
}
}
I am attempting to use Json.Net for this ... so I began with:
JObject jsonArtists = JObject.Parse(content);
This is where I am stuck. I have tried different approaches using a JArray
but am not sure exactly what syntax I need to use here, and how much of the lifting is going to be handled by Json.Net versus having to write out all of the various property mappings.
In this case I am interested in getting an array from the items
collection in the JSON and get this into a List<MyObject>
.
>()` but it's not even close to be fail proof :)
– dmay Jan 29 '16 at 00:43