gson

How to use gson deserialize to ArrayList in Kotlin

微笑、不失礼 提交于 2020-06-07 06:26:05
问题 I use this class to store data public class Item(var name:String, var description:String?=null){ } And use it in ArrayList public var itemList = ArrayList<Item>() Use this code to serialize the object val gs=Gson() val itemListJsonString = gs.toJson(itemList) And deserialize itemList = gs.fromJson<ArrayList<Item>>(itemListJsonString, ArrayList::class.java) But this method will give me LinkedTreeMap , not Item , I cannot cast LinkedTreeMap to Item What is correct way to deserialize to json in

How can I parse Json which starts with “/” in android using volley?

邮差的信 提交于 2020-05-30 08:13:10
问题 I am parsing json data from URl but it starts with "/". I have a data class which is a POJO class in the app. Here is my json file. /{ "data": [ { "id": "1", "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." }, { "id": "2", "text": "Felis donec et odio pellentesque diam volutpat commodo sed. Non arcu risus quis varius quam quisque. Nibh nisl condimentum id venenatis a condimentum vitae. Vel pharetra vel turpis

How to deal with “cannot be cast to class” error - GSON JAVA

◇◆丶佛笑我妖孽 提交于 2020-05-17 07:13:05
问题 i am trying to write my list to jtable in abstract model and then its return to me this error. In my opinion it could be cause by list format? name and amount are in wrong place. This is my full error message: Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: class com.google.gson.internal.LinkedTreeMap cannot be cast to class Model.Medicine (com.google.gson.internal.LinkedTreeMap and Model.Medicine are in unnamed module of loader 'app') There is a code: This is mine

How to get the value with GSON / Retrofit? [duplicate]

。_饼干妹妹 提交于 2020-05-17 04:21:08
问题 This question already has answers here : Using GSON to parse a JSON array (4 answers) Closed 2 years ago . How to extract the value of "text" by using GSON/Retrofit? { code: 200, lang: "en-ms", text: [ "Burung" ] } 回答1: 1 Create your model class public class ResponseItem { /** * code : 200 * lang : en-ms * text : ["Burung"] */ private int code; private String lang; private List<String> text; public int getCode() { return code; } public void setCode(int code) { this.code = code; } public

How to get the value with GSON / Retrofit? [duplicate]

泄露秘密 提交于 2020-05-17 04:20:06
问题 This question already has answers here : Using GSON to parse a JSON array (4 answers) Closed 2 years ago . How to extract the value of "text" by using GSON/Retrofit? { code: 200, lang: "en-ms", text: [ "Burung" ] } 回答1: 1 Create your model class public class ResponseItem { /** * code : 200 * lang : en-ms * text : ["Burung"] */ private int code; private String lang; private List<String> text; public int getCode() { return code; } public void setCode(int code) { this.code = code; } public

How to get the value with GSON / Retrofit? [duplicate]

China☆狼群 提交于 2020-05-17 04:19:02
问题 This question already has answers here : Using GSON to parse a JSON array (4 answers) Closed 2 years ago . How to extract the value of "text" by using GSON/Retrofit? { code: 200, lang: "en-ms", text: [ "Burung" ] } 回答1: 1 Create your model class public class ResponseItem { /** * code : 200 * lang : en-ms * text : ["Burung"] */ private int code; private String lang; private List<String> text; public int getCode() { return code; } public void setCode(int code) { this.code = code; } public

Expected BEGIN_ARRAY but was BEGIN_OBJECT when using GSON

故事扮演 提交于 2020-05-15 21:25:37
问题 Ok, I know that many of questions like that have been asked, but I have a specific question, which none of the others has. I want to know how I'd go on to parse following JSON file with GSON. { "BUYER": { "IGN": "MGlolenstine", "ProductID": "51" }, "BUYER": { "IGN": "MGlolenstine", "ProductID": "55" }, "BUYER": { "IGN": "MGlolenstine", "ProductID": "0" }, "BUYER": { "IGN": "MGlolenstine", "ProductID": "51" }, "BUYER": { "IGN": "MGlolenstine", "ProductID": "56" } } because when I use this code

NumberFormatException in GSON when converting String to double

倾然丶 夕夏残阳落幕 提交于 2020-05-15 01:18:28
问题 I am working with a JSON response that is improperly formatted. All fields are being returned as Strings . Unfortunately, I have no control over the return data . I am using Gson and attempting to parse a JSON object that includes a field like this: { [...] "cost": "9.25" } It should obviously be printed as a Number . When I try to parse this as a String , Number or double I get a NumberFormatException: com.google.gson.JsonSyntaxException: java.lang.NumberFormatException: [...] at com.myapp

Convert ArrayList with Gson to String

点点圈 提交于 2020-05-12 15:32:19
问题 I have an ArrayList which contains ArrayLists , each ArrayList in the Root list contains one ArrayList of Integers and one of Strings . I am converting it with Gson to a String to save it with SharedPreferences. But when I am reconverting it, Gson gives me 2.131558489E9 instead of the original int 2131558489 . How can I fix this Problem? Best Regards. Here is how I convert the ArrayList: levelPattern is the ArrayList String levelPatternGson = new Gson().toJson(levelPattern); And this is how I

Convert ArrayList with Gson to String

帅比萌擦擦* 提交于 2020-05-12 15:32:11
问题 I have an ArrayList which contains ArrayLists , each ArrayList in the Root list contains one ArrayList of Integers and one of Strings . I am converting it with Gson to a String to save it with SharedPreferences. But when I am reconverting it, Gson gives me 2.131558489E9 instead of the original int 2131558489 . How can I fix this Problem? Best Regards. Here is how I convert the ArrayList: levelPattern is the ArrayList String levelPatternGson = new Gson().toJson(levelPattern); And this is how I