Posts

Showing posts from August, 2021

Android parse JSON Key dynamically

Image
  JavaScript Object Notation   JSON stands for JavaScript Object Notation. It is an independent data exchange format and is the best alternative for XML. As a refresher, there are four main components of a JSON file: JSON array, JSON object, Key, and Value. Usually, we need to get the value of the specified key. But the key is sometimes vital, and you need to get it like some Currency Exchange APIs. In this article, we will know how to parse a key dynamically by tackling two examples. First, Parse the JSON key with the value: In the first example, we need to get the currency code which are the keys.   Parse the JSON key with the value In the above image, the currency codes are inside the red box and the double values beside them are their rates. So, to create our model class for it, you will define a Map of String as a key and double as a value representing currency codes and their rates. @SerializedName( "rates" ) val rates: Map<String, Double>,...