2015-01-31 10 views
-2

저는 프로그래밍에 익숙하지 않고 질문이 있습니다. JSON 파일에서 데이터를 가져오고 싶지만 액세스하는 방법을 모르겠습니다.JSON 파일에서 데이터를 가져 오는 방법은 무엇입니까?

이것은 JSON 파일이며, 원하는 데이터는 'uri'입니다.

{ 
    "albums" : { 
    "href" : "https://api.spotify.com/v1/search?query=elephant+the+white+stripes&offset=0&limit=1&type=album", 
    "items" : [ { 
     "album_type" : "album", 
     "available_markets" : [ "AD", "AR", "AT", "AU", "BE", "BG", "BO", "BR", "CH", "CL", "CO", "CR", "CY", "CZ", "DE", "DK", "DO", "EC", "EE", "ES", "FI", "FR", "GB", "GR", "GT", "HN", "HU", "IE", "IS", "IT", "LI", "LT", "LU", "LV", "MC", "MX", "NI", "NL", "NO", "NZ", "PA", "PE", "PL", "PT", "PY", "RO", "SE", "SI", "SK", "SV", "TR", "UY" ], 
     "external_urls" : { 
     "spotify" : "https://open.spotify.com/album/0rRNLpdA8nA8Sm8Fk490b9" 
     }, 
     "href" : "https://api.spotify.com/v1/albums/0rRNLpdA8nA8Sm8Fk490b9", 
     "id" : "0rRNLpdA8nA8Sm8Fk490b9", 
     "images" : [ { 
     "height" : 618, 
     "url" : "https://i.scdn.co/image/7c7667a66c195842a18341b754ddff1e57295774", 
     "width" : 640 
     }, { 
     "height" : 290, 
     "url" : "https://i.scdn.co/image/4d761858e1541ef386a0b8a9f1047805db754a6d", 
     "width" : 300 
     }, { 
     "height" : 62, 
     "url" : "https://i.scdn.co/image/7b5248fbae00aae3c9d6d01abb24b32578aa3f31", 
     "width" : 64 
     } ], 
     "name" : "Elephant", 
     "type" : "album", 
     "uri" : "spotify:album:0rRNLpdA8nA8Sm8Fk490b9" 
    } ], 
    "limit" : 1, 
    "next" : "https://api.spotify.com/v1/search?query=elephant+the+white+stripes&offset=1&limit=1&type=album", 
    "offset" : 0, 
    "previous" : null, 
    "total" : 3 
    } 
} 

이 지금까지 내 코드이고, 나는 HREF에 저장되어있는 데이터를 얻을.

WebClient c = new WebClient(); 

var getData = c.DownloadString("https://api.spotify.com/v1/search?q=elephant%20the%20white%20stripes&type=album&limit=1"); 

JObject o = JObject.Parse(getData); 

Console.WriteLine("href: " + o["albums"]["href"]); 
+0

를 사용할 수 있습니다. 거기에 톤이 있어야합니다. –

답변

0
var result = o["albums"]["items"][0]["uri"]; 

은 URI는 항목이며, 여기에는 하나 개의 항목 만입니다. 그 이상의 경우 [0]을 변경해야합니다.

+0

정말 고마워요! –

0

당신은 내가 튜토리얼 Google에 제안 해 드릴 것 JSON.net (Nuget 패키지 here)

var getData = c.DownloadString("https://api.spotify.com/v1/search?q=elephant%20the%20white%20stripes&type=album&limit=1"); 

dynamic data = JsonConvert.DeserializeObject(getData); // or JObject.Parse(getData) 

Console.WriteLine(data.albums.items[0].uri); 
관련 문제