Hi, I’m trying to convert ArrayList with GSON to JSON. I have a json as a result, but not the json I expected. I need this to use Fuel.post
val requestParams = ArrayList<Pair<String, Any>>()
val coordonnee = requestParams.add(Pair(“coordonnees”, Singleton.instance.coordonnee!!.toParam()))
val details = requestParams.add(Pair(“details”, result))
val price = requestParams.add(Pair(“price”, price.toString()))println(“requestParams : $requestParams”)
val gson = GsonBuilder().setPrettyPrinting().create()
val json: String = gson.toJson(requestParams)
My array :
[
(coordonnees,
[(genre, M.), (nom, nom), (adresse, adresse), (ville, ville), (cp, 45460), (email, test@test.fr), (tel, 0611223344)]
),
(details,
“value”
),
(price, 0)
]
The json I get. Why do I have “first” and “second” all the time ?
{
“first”: “coordonnees”,
“second”: [{
“first”: “genre”,
“second”: “M.”
},
{
“first”: “nom”,
“second”: “nom”
},
{
“first”: “adresse”,
“second”: “adresse”
},
{
“first”: “ville”,
“second”: “ville”
},
{
“first”: “cp”,
“second”: “45”
},
{
“first”: “email”,
“second”: “test@test.fr”
},
{
“first”: “tel”,
“second”: “0677039672”
}
]
}, {
“first”: “details”,
“second”: “value”
}, {
“first”: “price”,
“second”: “0”
}]