2013-12-04 2 views
0

Я получаю следующие данные с апи вызова -Invalid Json примитивная ошибка - апи вызов результат

[{ 
    "generated_at": 1371490821, 
    "status": "success", 
    "station_id": 1, 
    "station_name": "Hits Radio FM", 
    "developer_id": 24, 
    "count": 5, 
    "refresh_url": "https://api.xxx.com/1/GET/nowplaying.json?api_key=[YOUR_API_KEY]&station_id=1&count=5", 
    "next_results_url": "https://api.xxx.com/1/GET/nowplaying.json?api_key=[YOUR_API_KEY]&station_id=1since_id=85", 
    "since_id": 85, 
    "tracks": { 
     "0": [{ 
      "id": 80, 
      "artist": "Robbie Williams", 
      "artist_id": 314, 
      "title": "Candy" 
      "likes": 215, 
      "youtube_id": "gtOV7bp-gys", 
      "coverart_url": "http://25.media.tumblr.com/tumblr_mdukt9rJoI1rj7xj3o1_500.jpg", 
      "spotify_url": "https://play.spotify.com/track/6cskzfZWgrgd8hv74fHd9o", 
      "itunes_url": "https://itunes.apple.com/nl/album/candy-single/id558817147", 
      "playedtime": 1371490752, 
      "likedByUser": 0 
     }], 
     "1": [{ /* the same layout as above */ }], 
     "2": [{ /* the same layout as above */ }], 
     "3": [{ /* the same layout as above */ }], 
     "4": [{ /* the same layout as above */ }] 
    } 
}] 

Когда я пытаюсь десериализациями этих данных с помощью JavaScriptSerializer, я получаю сообщение об ошибке «Invalid JSON примитивного» ,

Может кто-нибудь помочь мне решить эту проблему.

У меня есть следующие классы, используемые для хранения данных.

Public Class ResponseTrackInfo 
    Dim id As Integer 
    Dim artist As String 
    Dim artist_id As Integer 
    Dim title As String 
    Dim likes As Integer 
    Dim youtube_id As String 
    Dim coverart_url As String 
    Dim spotify_url As String 
    Dim itunes_url As String 
    Dim playedtime As Integer 
    Dim likedByUser As Integer 
End Class 

и

Public Class ResponseNowPlayingInfo 
    Dim generated_at As Integer 
    Dim status As String 
    Dim station_id As Integer 
    Dim station_name As String 
    Dim developer_id As Integer 
    Dim count As Integer 
    Dim refresh_url As String 
    Dim next_results_url As String 
    Dim since_id As Integer 
    Dim tracks As List(Of ResponseTrackInfo) 

    Public Sub New() 
     tracks = New List(Of ResponseTrackInfo) 
    End Sub 
End Class 

и код

Private Sub CallApiToGetLiveEvents() 
     Dim apiResponse As WebResponse 
     Dim request As HttpWebRequest 
     Dim apiUrl As String = ConfigurationManager.AppSettings("My_URL") 

     Dim apiKey As String = ConfigurationManager.AppSettings("My_ApiKey") 
     Dim stationId As String = ConfigurationManager.AppSettings("My_StationId") 
     apiUrl = String.Format(apiUrl, apiKey, stationId) 


     Dim uri As New Uri(apiUrl) 
     request = WebRequest.Create(uri) 
     apiResponse = request.GetResponse() 

     If Not (apiResponse Is Nothing) Then 
      Dim data1(apiResponse.ContentLength) As Byte 

      apiResponse.GetResponseStream().Read(data1, 0, data1.Length) 

      Dim d = Encoding.ASCII.GetString(data1) 

      Dim ser As New JavaScriptSerializer 
      Dim decoded = ser.Deserialize(Of List(Of ResponseNowPlayingInfo))(d) 

     End If 
    End Sub 

ответ

0

Вы, наверное, не хватает запятой после

"title": "Candy" 

в вашем JSON объект, который дает парсер на самом деле трудное время для разбора этого t как JSON. :)

Смежные вопросы