Spotify Android SDK搜索曲目编号

时间:2015-12-22 04:28:47

标签: android spotify libspotify

我目前已连接到Spotify sdk,我目前正在寻找能够让用户搜索曲目并且它将返回曲目编号。我已经按照sdk指南跟踪一首歌,我得到了响应作为JSON响应,但是当我尝试从我得到的字符串响应在android中创建一个JSONArray时,它告诉我它无法创建JSONArray。我目前得到的回应是这样的

{
  "info": {
    "num_results": 601,
    "limit": 100,
    "offset": 0,
    "query": "what do you mean",
    "type": "track",
    "page": 1
  },
  "tracks": [
    {
      "album": {
        "released": "2015",
        "href": "spotify:album:7fZH0aUAjY3ay25obOUf2a",
        "name": "Purpose (Deluxe)",
        "availability": {
          "territories": "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 HK HN HR HU IE IS IT LI LT LU LV MC MT NI NL NO NZ PA PE PH PL PT PY RO SE SI SK SV TR TW UY"
        }
      },
      "name": "What Do You Mean?",
      "popularity": "0.97",
      "external-ids": [
        {
          "type": "isrc",
          "id": "USUM71511919"
        }
      ],
      "length": 205.68,
      "href": "spotify:track:3pzjHKrQSvXGHQ98dx18HI",
      "artists": [
        {
          "href": "spotify:artist:1uNFoZAHBGtllmzznpCI3s",
          "name": "Justin Bieber"
        }
      ],
      "track-number": "3"
    },
    {
      "album": {
        "released": "2015",
        "href": "spotify:album:6Fr2rQkZ383FcMqFyT7yPr",
        "name": "Purpose (Deluxe)",
        "availability": {
          "territories": "CA MX US"
        }
      },
      "name": "What Do You Mean?",
      "popularity": "0.93",
      "external-ids": [
        {
          "type": "isrc",
          "id": "USUM71511919"
        }
      ],
      "length": 205.68,
      "href": "spotify:track:4B0JvthVoAAuygILe3n4Bs",
      "artists": [
        {
          "href": "spotify:artist:1uNFoZAHBGtllmzznpCI3s",
          "name": "Justin Bieber"
        }
      ],
      "track-number": "3"
    },
    {
      "album": {
        "released": "2015",
        "href": "spotify:album:2hL8vuRtlo75Wr9PyZI5Jb",
        "name": "What Do You Mean?",
        "availability": {
          "territories": ""
        }
      },
      "name": "What Do You Mean?",
      "popularity": "0.87",
      "external-ids": [
        {
          "type": "isrc",
          "id": "USUM71511919"
        }
      ],
      "length": 207.546,
      "href": "spotify:track:1ds2QsfhAAfRiaFMGDzrdb",
      "artists": [
        {
          "href": "spotify:artist:1uNFoZAHBGtllmzznpCI3s",
          "name": "Justin Bieber"
        }
      ],
      "track-number": "1"
    },
    {
      "album": {
        "released": "2015",
        "href": "spotify:album:7fZH0aUAjY3ay25obOUf2a",
        "name": "Purpose (Deluxe)",
        "availability": {
          "territories": "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 HK HN HR HU IE IS IT LI LT LU LV MC MT NI NL NO NZ PA PE PH PL PT PY RO SE SI SK SV TR TW UY"
        }
      },
      "name": "What Do You Mean? - Acoustic",
      "popularity": "0.85",
      "external-ids": [
        {
          "type": "isrc",
          "id": "USUM71516855"
        }
      ],
      "length": 203.8,
      "href": "spotify:track:5bldrrpdHrTeaWNT1Kp5xs",
      "artists": [
        {
          "href": "spotify:artist:1uNFoZAHBGtllmzznpCI3s",
          "name": "Justin Bieber"
        }
      ],
      "track-number": "19"
    },
    {
      "album": {
        "released": "2015",
        "href": "spotify:album:6Fr2rQkZ383FcMqFyT7yPr",
        "name": "Purpose (Deluxe)",
        "availability": {
          "territories": "CA MX US"
        }

我的android代码看起来像这样

 try {
            response = httpClient.execute(httpPost);
            responseBody = EntityUtils.toString(response.getEntity());
            try {
                jsonArray = new JSONArray(responseBody);
            } catch (JSONException e) {
                e.printStackTrace();
            }

提前感谢您的帮助 〜Rockyfish

1 个答案:

答案 0 :(得分:0)

这样做

JSONObject jObj;
try {
        jObj = new JSONObject(responseBody);
    } catch (JSONException e) {
        e.printStackTrace();
    }