简体   繁体   中英

how to convert string array JSON to be ArrayList in Kotlin?

so I have this JSON in string format:

[
  "1.0",
  "1.1",
  "1.2"
]

but I need to convert it to ArrayList In Kotlin ? I have tried to find, but most of the answer are in Java. if using gson in Java maybe it will be like this. but I am a beginner and I failed to convert the code below to Kotlin

Gson gson = new GsonBuilder().create();
ArrayList<String> theList = gson.fromJson(stringObject, new TypeToken<ArrayList<String>>(){}.getType())

what should I do to convert that json string to array list in Kotlin ?

Maybe this is the kotlin code you want, converted from your Java code:

val gson = GsonBuilder().create()
val theList = gson.fromJson<ArrayList<String>>(stringObject, object :TypeToken<ArrayList<String>>(){}.type)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM