我尝试过其他相同问题的许多建议,但没有帮助,我怎样才能成功运行此测试:
@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)
答案 0 :(得分:1)
试试这个:
val json: String = "[{\"Id\":2,\"Text\":\"Математика\"},{\"Id\":5,\"Text\":\"Физика\"}]"
val results: List<Person> = gson.fromJson(json , Array<Person>::class.java).toList()