Zakhar
03/07/2024, 3:26 PMMap<String, JsonElement?>.
All strings in values of the map will have quotes at the start and at the end. E.g instead of just consumable a string will look like "consumable" How to avoid this?
Tried to use org.json.JSONObject. And in this case the result looks correctly.Zakhar
03/07/2024, 3:42 PM"{\"af_content_id\":\"currency.credits.1\",\"af_content_type\":\"consumable\",\"af_revenue\":1.59,\"af_currency\":\"RUB\"}"
I generate it from javascript code. The JSON.stringify function.Adam S
03/07/2024, 3:44 PMAdam S
03/07/2024, 3:44 PMZakhar
03/07/2024, 3:51 PMHow do you generate that string from JSON stringify?The source object:
{af_content_id: "currency.credits.1", af_content_type: "consumable", af_revenue: 1.59, af_currency: "RUB"}
Just a valid js object.Zakhar
03/07/2024, 3:53 PMMap<String, String?>. Maybe JsonElement is the issueephemient
03/07/2024, 7:54 PMJsonObject, which is a subtype of Map<String, JsonElement>Zakhar
03/08/2024, 2:52 PMJsonObject did not help. Still get the same result 😕chr
03/10/2024, 6:08 PMval json: JsonElement = Json.parseToJsonElement(string)
val contentType1 = json.jsonObject["af_content_type"]!!.jsonPrimitive.content
val map: Map<String, JsonElement> = Json.decodeFromString(string)
val contentType2 = map["af_content_type"]!!.jsonPrimitive.contentchr
03/10/2024, 6:10 PMcontent and not toString(), because the toString method inserts those quotes to denote that it's a string primitive and not a number primitive (ie: if the content was "42", the quotes disambiguate the string "42" from the number 42
public override fun toString(): String =
if (isString) buildString { printQuoted(content) }
else contentZakhar
03/11/2024, 9:14 AMtoString function of JsonElement. The AppsFlyer lib requires a Map to log events https://dev.appsflyer.com/hc/docs/android-sdk-reference-appsflyerlib#logevent
And looks like the lib uses the toString function somewhere inside.
Thanks for your help.