android - com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 2 path -


i have tries many suggestions other same questions not help, how can run test successfully:

@test fun isjsoncorrectpersonconvert() {     val gson = gsonbuilder().create()     val json = gson.tojson("[{\"id\":2,\"text\":\"Математика\"},{\"id\":5,\"text\":\"Физика\"}]")     val results = gson.fromjson(json, array<person>::class.java)     assert.assertnotnull(results)     assert.assertnotnull(results[0].id)     assert.assertnotnull(results[0].text)     system.out.println(results.tostring()) }  data class person(val id: int,val text:string) 

try :

val json: string = "[{\"id\":2,\"text\":\"Математика\"},{\"id\":5,\"text\":\"Физика\"}]" val results: list<person> = gson.fromjson(json , array<person>::class.java).tolist() 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -