GSON. How to convert json object to json array?

前端 未结 7 1866
没有蜡笔的小新
没有蜡笔的小新 2021-02-08 15:20

Now I am getting this JSON from API:

{\"supplyPrice\": {
        \"CAD\": 78,
        \"CHF\": 54600.78,
        \"USD\": 20735.52
      }}

But

7条回答
  •  死守一世寂寞
    2021-02-08 15:59

    We are only one line of code away from converting jsonObjects to arrays(Not jsonArrays but after making it a arrayList you can create jsonArray too,easily.)

    fun jsonObjectToArray(jsonObject : JsonObject,listTypeClass : Class) = arrayListOf().apply { jsonObject.keySet().forEach { this.add(Gson().fromJson(jsonObject.get(it).toString(),listTypeClass))}}
    

提交回复
热议问题