0

我正在尝试使用 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[??][??]...;

有任何想法吗?谢谢!

4

1 回答 1

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();
    }
于 2017-07-29T01:24:49.123 回答