Nesneleri içeren bir JSON dizesini GSON kullanarak nesnelere dönüştürmek için mücadele.Java - Nesneleri nesnelere Gso
JSON dizisi
[
{"_id":"11111",
"_owner":"2222",
"name":"S32B - TankFever",
"__v":0,
"slots":[],
"members":
[
{"_email":"[email protected]",
"key":"XXX",
"_id":"33333",
"accepted":false
},
{"_email":"[email protected]",
"key":"XXX",
"_id":"44444",
"accepted":false}
]
}, and some more.
]
dizi G 'çizelgesi' olarak adlandırılan nesneleri içerir. Ve her bir zaman çizelgesi 'Yuva' ve 'Üye' olarak adlandırılan bir dizi nesne içerir.
sınıflar
Zaman Çizelgesi
private String _owner;
private String name;
private Slot[] slots;
private Member[] members;
Üye
private String _email;
private String key;
private boolean accepted;
Yuvası (hala boş) diye düşündüm
Kod çalışması gerekir:
String jsonString = response.body().string();
Type type = new TypeToken<List<Timesheet>>(){}.getType();
List<Timesheet> inpList = new Gson().fromJson(jsonString, type);
for (int i=0;i<inpList.size();i++) {
Timesheet x = inpList.get(i);
System.out.println(x);
}
hata
04-09 23:13:17.242 1594-1594/com.example.jim.app I/System.out: java.lang.IllegalStateException: closed
04-09 23:13:17.242 1594-1594/com.example.jim.app I/System.out: at okhttp3.internal.http.Http1xStream$FixedLengthSource.read(Http1xStream.java:378)
04-09 23:13:17.242 1594-1594/com.example.jim.app I/System.out: at okio.Buffer.writeAll(Buffer.java:956)
04-09 23:13:17.243 1594-1594/com.example.jim.app I/System.out: at okio.RealBufferedSource.readByteArray(RealBufferedSource.java:92)
04-09 23:13:17.243 1594-1594/com.example.jim.app I/System.out: at okhttp3.ResponseBody.bytes(ResponseBody.java:83)
04-09 23:13:17.243 1594-1594/com.example.jim.app I/System.out: at okhttp3.ResponseBody.string(ResponseBody.java:109)
04-09 23:13:17.243 1594-1594/com.example.jim.app I/System.out: at com.example.jim.app.model.User.getOwnedTimesheets(User.java:169)
04-09 23:13:17.243 1594-1594/com.example.jim.app I/System.out: at com.example.jim.app.fragment.TimesheetsFragment.initializeTimesheetsListView(TimesheetsFragment.java:91)
04-09 23:13:17.243 1594-1594/com.example.jim.app I/System.out: at com.example.jim.app.fragment.TimesheetsFragment.onCreateView(TimesheetsFragment.java:73)
I (O GSON hakkında hiçbir şey söylemez ancak ayıklamaya burada bir istisna atar etmez) alırsınız bazı ek bilgiye ihtiyaç duyulması halinde, bu soruyu güncelleyecektir en kısa sürede!
Teşekkür
aynı sınıf kullanmalıdır
yerine özel durum oluşturur
Timesheet
atıfta yana işe yaramadığını mı düşünüyorsun? – Savior@Pillar Üzgünüm, alacağım hata mesajını tamamen unuttum! –
Bunun JSON veya Gson ile ilgisi yoktur. Yanıt akışınız kapalı. – Savior