如何访问Soundcloud JSON数据

时间:2013-08-25 18:45:14

标签: json soundcloud

我正在尝试使用soundcloud API并尝试从我的JSON对象中提取所有播放列表标题,以创建包含引用的列表。实际上我没有很多JSON经验,因此我无法通过解码的JSON数组调用任何变量......

http://api.soundcloud.com/users/55607614/playlists.json?client_id=YOUR_CLIENT_ID

我已经通过http://jsonviewer.stack.hu/查看了结构,但它并没有真正帮助我......

$json = json_decode(file_get_contents("http://api.soundcloud.com/users/55607614/playlists.json?client_id=YOUR_CLIENT_ID"));
echo $json[??][??]...;

有什么想法吗?谢谢!

1 个答案:

答案 0 :(得分:0)

private SCPlaylistObject playListObject, plTestObject;
public string TrackList;
private List<SCTrackObjects> TListTest;

/// <summary>
/// Deserializes JSON data into object from string
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="jsonString"></param>
    /// <returns>json object</returns>
    public static T Deserialize<T>(string jsonString)
    {
        DataContractJsonSerializer deserializer = new DataContractJsonSerializer(typeof(T));

        MemoryStream MemStream = new MemoryStream(Encoding.Unicode.GetBytes(jsonString));

        T result = (T)deserializer.ReadObject(MemStream);

        return result;


    }


public  async Task<string> GetUserTracks() // Async Call to get user id
    {
        try
        {
            responseText = await GetjsonStream();

            SCUserID = userObject.id;

            TrackList = await GetTracks();


            TList = Deserialize<List<SCTrackObjects>>(TrackList);

            return TrackList;


        }
        catch (Exception ex)
        { 
            Console.Out.WriteLine(ex.Message);
            return ex.Message;
        }


public async Task<string> GetTracks() //Function to read from given url
 {
    HttpClient client = new HttpClient();
    string url = SCLink + SCAPIUsers + SCUserID + "/tracks?client_id=" + soundcloudAPI;
    HttpResponseMessage response = await client.GetAsync(url);
    HttpResponseMessage v = new HttpResponseMessage();
    return await response.Content.ReadAsStringAsync();
  }
}

    public async Task<string> GetjsonStream() //Function to read from given url
    {
        HttpClient client = new HttpClient();
        string url = SCLink + SCAPIUsers + SCNameField + ".json?client_id=" + soundcloudAPI;
        HttpResponseMessage response = await client.GetAsync(url);
        HttpResponseMessage v = new HttpResponseMessage();
        return await response.Content.ReadAsStringAsync();
    }