2016-03-09 34 views
0

其實我正在訪問列表視圖中的歌曲詳細信息,現在我想將它們存儲在我的服務器上(整個列表項目)。我是Android新手。請幫幫我。如何列出要在服務器上存儲的歌曲詳細信息

我做了PHP的Web服務這需要JSON

需要輸入:

$inputJSON = '{ 
    "currentTimeStamp" : 1446786632.036515, 
    "songData" : [ 
     { 
      "SongID" : "2", 
      "status" : "1", 
      "albumTitle" : "Zid", 
      "playbackDuration" : 289.802, 
      "artist" : "Sharib-Toshi, Sunidhi Chauhan, Sharib Sabri", 
      "podcastTitle" : "Zid", 
      "assetURL" : "ipod-library:\/\/item\/item.mp3?id=4206809166388889270", 
      "isSelected" : "1", 
      "albumArtist" : "Sharib-Toshi", 
      "title" : "Tu Zaroori (Duet) - WapLoft.`enter code here`Com" 
     } 
    ], 
    "UserID" : "2" 
}'; 

回答

0

如果使用光標,那麼你將不得不通過遊標運行和創作樂曲的JSON數組。

首先創建一個JSONArray如下

JSONArray songArray= new JSONArray(); 

現在把你的所有歌曲在陣列中,你會在任何陣列

songsArray.put(eachSongsJsonObject); 

其中

eachSongsJsonObject = new JSONObject(); 
eachSongsJsonObject.put("SongID",<the song id you got from cursor>); 
eachSongsJsonObject,put("albumTitle",<album title>); 

等做直到你獲得所有的數據。一旦所有做到這一點,你的JSON數組完成創建主的JSONObject發送如下

JSONObject jsonObject= new JSONOBject(); 
jsonObject.put("songData",songArray); 
jsonObject.put("currentTimeStamp",<your time stamp>); 

然後,你可以發送的JSONObject到您的服務器,並將其保存在那裏。將JSON發送到您的服務器使用volley庫進行JsonObjectRequest調用。您可以按照以下鏈接執行排除操作。

https://developer.android.com/training/volley/index.html

相關問題