1

Here is my serivce interface:

@POST("/serachtracks")
Call<List<Track>> searchTracks(@Header("Authentification") String accessToken, @Query("tag") String tag);

Here is class Track:

public class Track implements Serializable {

@SerializedName("track_id")
public int id;

@SerializedName("track_title")
public String title;

@SerializedName("track_tags")
public String tags;

// ... GETERS & SERTERS
}

JSON that i receive from server:

[{"track_id":9833,"track_title":"A some title","track_tags":"#tags"}, {...}, {...}]

But i get this error:

 com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $
                                                             at com.google.gson.Gson.fromJson(Gson.java:873)
                                                             at com.google.gson.Gson.fromJson(Gson.java:826)

Please help! Thanks!

  • Did you see this http://stackoverflow.com/questions/16380367/gson-expected-begin-array-but-was-string-at-line-1-column-62 – TechnoBlahble Feb 07 '16 at 03:59
  • But I get from soundcloud the same JSON data and it works: – Urma Tilekov Feb 07 '16 at 05:08
  • May be the problem in my server. My response from server looks like this: – Urma Tilekov Feb 07 '16 at 05:19
  • `code $res = array(); for ($i = 0; $i < 4; $i++) { $tracks = array( 'track_id' => 1, 'track_title' => 'ABC', 'track_tags' => 'tgs' ); array_push($res, $tracks); } header('Content-Type: application/json;'); echo json_encode($res);` – Urma Tilekov Feb 07 '16 at 05:22

1 Answers1

0

The problem was in my response from my server:

echo json_encode($array);

is not good way.