First: this is my first time using GSON.
Trying to parse some JSON, I got “incompatible types”…
Gson gson = new Gson();
PlayerData data = gson.fromJson(response, PlayerData.class); // Incompatible types...
PlayerData is an inner class:
class PlayerData {
public Point position;
public String mapname;
public int level;
public PlayerData() {}
}
What causes it? In the GSON docs there is clearly a method public <T> T fromJson(String json, and I am doing at (AFAIK) just like Google in it’s GSON User Guide.
Class<T> classOfT)
throws JsonSyntaxException
Edit:
XCode was doing something strange, when I tried to compile this with Terminal everything worked, except for my request to the server, what resulted in a couple of NPE’s, because response remained empty. Thanks to maaartinus I learned that there shouldn’t be an compiler error so I tried to compile it without XCode.
For me it compiles, but I had to replace
GSONbyGson. Either you were sloppy when writing this question or you’re using some “GSON” I’ve never heard about.Is your
responseaString???Once you get it running, you’ll need the answer by Vrushank Desai.