I have this class:
public class MyClass {
public int number;
public long date;
}
I have a JSON string that I'm converting to a MyClass object by doing:
String s = "{\"Number\":2,\"Date\":1444953600}";
MyClass temp = new Gson().fromJson(s, MyClass.class);
However, I'm getting the following exception:
Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 2 path $
at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:387)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:210)
What am I doing wrong?
EDIT
As requested, this is the complete code:
URL url = new URL(some_url);
HttpsURLConnection connection = (HttpsURLConnection)url.openConnection();
connection.setRequestMethod("GET");
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuffer response = new StringBuffer();
String inputLine;
while ((inputLine = reader.readLine()) != null) {
response.append(inputLine);
}
reader.close();
MyClass temp = new Gson().fromJson(response.toString(), MyClass.class);
And the update class is:
public class MyClass implements Serializable {
@SerializedName("Number")
public int number;
@SerializedName("Date")
public long date;
}
intis you are extractingString