Spotify Android SDK 正在搜索曲目编号
Spotify Android SDK Searching for track number
我目前连接到 Spotify sdk,我目前希望能够让用户搜索曲目,它将 return 曲目编号。我已经按照 sdk 指南跟踪歌曲,并且得到的响应是 JSON 响应,但是当我尝试从我得到的字符串响应中创建 JSONArray in android 时,它告诉我它无法创建 JSON 数组。我目前得到的回应是这样的
{
"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();
}
感谢您提前的帮助
~石斑鱼
这样做
JSONObject jObj;
try {
jObj = new JSONObject(responseBody);
} catch (JSONException e) {
e.printStackTrace();
}
我目前连接到 Spotify sdk,我目前希望能够让用户搜索曲目,它将 return 曲目编号。我已经按照 sdk 指南跟踪歌曲,并且得到的响应是 JSON 响应,但是当我尝试从我得到的字符串响应中创建 JSONArray in android 时,它告诉我它无法创建 JSON 数组。我目前得到的回应是这样的
{
"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();
}
感谢您提前的帮助 ~石斑鱼
这样做
JSONObject jObj;
try {
jObj = new JSONObject(responseBody);
} catch (JSONException e) {
e.printStackTrace();
}