A
A
awox2022-02-15 22:58:09
Android
awox, 2022-02-15 22:58:09

How to parse nested JSON objects?

There is json data in the file https://www.cbr-xml-daily.ru/daily_json.js , they are received and processed:

val data = response.toString()
val valute = JSONObject(data).getJSONObject("Valute")
println(valute.toString())


Before processing:
{
    "Date": "2022-02-12T11:30:00+03:00",
    "PreviousDate": "2022-02-11T11:30:00+03:00",
    "PreviousURL": "\/\/www.cbr-xml-daily.ru\/archive\/2022\/02\/11\/daily_json.js",
    "Timestamp": "2022-02-13T23:00:00+03:00",
    "Valute": {
        "AUD": {
            "ID": "R01010",
            "NumCode": "036",
            "CharCode": "AUD",
            "Nominal": 1,
            "Name": "Австралийский доллар",
            "Value": 53.5105,
            "Previous": 53.7266
        },
...


After println(value.toString()):
{
        "AUD": {
            "ID": "R01010",
            "NumCode": "036",
            "CharCode": "AUD",
            "Nominal": 1,
            "Name": "Австралийский доллар",
            "Value": 53.5105,
            "Previous": 53.7266
        },
...


Question: How to parse further in depth?
How to get the values ​​for each currency to display as a table:
"ID" "NumCode" "CharCode" "Nominal" "Name" "Value" "Previous" 
AUD   "R01010"   "036"   "AUD"   1   "Австралийский доллар"   53.5105   53.7266
AZN   ...
GBP   ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Prokhorovich, 2022-02-16
@alexgp13

And who is stopping you from getting objects further?
val aud = value.getJSONObject("AUD")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question