https://kotlinlang.org logo
#android
Title
# android
r

Remon Shehata

05/09/2021, 2:05 PM
is there a way to calculate the size of JSON in bytes using Kotlin?
n

Nimish Nandwana

05/09/2021, 2:31 PM
Is the json coming in api response or stored in a file ? Which networking library are you using ?
r

Remon Shehata

05/09/2021, 3:19 PM
I create the JSON by myself using Moshi. and I want to check the size before sending it to the API. I am using retrofit
s

Saul Alonso Palazuelos Alvarado

05/09/2021, 4:29 PM
Do you mean a JSON String?
r

Remon Shehata

05/09/2021, 4:46 PM
Yes! well JSON object is simply a string, right?
c

Colton Idle

05/09/2021, 5:18 PM
Wouldn't the calculated size change if you're using gzip?
r

Remon Shehata

05/09/2021, 5:57 PM
I guess you are right! I tried a couple of things and the size is never accurate .
3 Views