folgenden Ausschnitt stürzt mit Caused by: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING
Um von json stürzt sofort
GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create();
String jsonObjString = gson.toJson(customClassInstance, MyCustomClass.class);
gson.fromJson(jsonObjString, MyCustomClass.class); // Crashes here
Warum JSon? Wenn ich das jsonObjString
drucke, scheint es in Ordnung.
Und die Codierung/Decodierung scheint richtig. Was ist das Problem?
Update:
public class MyCustomClass {
@SerializedName(“customer_city”)
private String customerCity;
@SerializedName(“customer_id”)
private String customerId;
private LocalDate entry;
@SerializedName(“customer_income”)
private double customerIncome;
private String[] cards;
@SerializedName(“customer_name")
private String customerName;
}
was bedeutet u von "Absturz"? ist es eine Ausnahme, wenn ja, bitte posten Sie das auch. –
Es ist wahrscheinlich ein Konflikt zwischen JsonString und der Java-Klasse. – Jagrut
@RamanShrivastava: Die Ausnahme ist in der OP – Jim