Hi, I am trying to fetch JSON data from an API in ...
# android
n
Hi, I am trying to fetch JSON data from an API in my kotlin android project. I tried researching about it but was unable to find a direct and easy method. Can anyone help me regarding the same? I am trying to get the City Name and Temperature only.
v
User GSON library to map json with POJO
👍 2
m
You may want to look at GSON library. You can use SerializedName annotation and/or a custom deserializer
👍 1
f
Use Moshi/gson or Kotlin serialization as an adapter for retrofit to serialization of the response
c
For a bit of an example, have a look at this SO question and accepted answer. https://stackoverflow.com/questions/60470109/kotlin-jsons-array-is-not-a-primitive-array/60476088#60476088
💯 1
h
Don't use GSON... Its dead. Use Kotlinx Serialization or Moshi or Jackson
☝️ 1
👍 1