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
Post a Comment