Android Question holidays Api

FrankDev

Active Member
Licensed User
Longtime User
hello

I have an api to query holidays in Germany.
I would like to write this to a file and then read it from there into the Very Good AS Scheduler

Depending on the 'bundesland', something like cantons in Switzerland or states in the USA, there are a different number of holidays.

the api:

But somehow the structure seems to me to be very .... hmmmm.

is there a better method to read this in a loop ?
 

DonManfred

Expert
Licensed User
Longtime User
The Api gives you a MAP with the Holidays as a Keyname.
I´ve named this Map Feiertag

B4X:
Dim parser As JSONParser
parser.Initialize(<text>)
Dim jRoot As Map = parser.NextObject
Dim feiertag As Map = jRoot.Get("Tag der Deutschen Einheit")
Dim datum As String = feiertag.Get("datum")
Dim hinweis As String = feiertag.Get("hinweis")

Dim feiertag As  Map = jRoot.Get("Christi Himmelfahrt")
Dim datum As String = feiertag.Get("datum")
Dim hinweis As String = feiertag.Get("hinweis")

Dim feiertag As Map = jRoot.Get("2. Weihnachtstag")
Dim datum As String = feiertag.Get("datum")
Dim hinweis As String = feiertag.Get("hinweis")

Dim feiertag As Map = jRoot.Get("Ostermontag")
Dim datum As String = feiertag.Get("datum")
Dim hinweis As String = feiertag.Get("hinweis")

Dim feiertag As Map = jRoot.Get("Tag der Arbeit")
Dim datum As String = feiertag.Get("datum")
Dim hinweis As String = feiertag.Get("hinweis")

Dim feiertag As Map = jRoot.Get("Allerheiligen")
Dim datum As String = feiertag.Get("datum")
Dim hinweis As String = feiertag.Get("hinweis")

Dim feiertag As Map = jRoot.Get("Karfreitag")
Dim datum As String = feiertag.Get("datum")
Dim hinweis As String = feiertag.Get("hinweis")

Dim feiertag As Map = jRoot.Get("Pfingstmontag")
Dim datum As String = feiertag.Get("datum")
Dim hinweis As String = feiertag.Get("hinweis")

Dim feiertag As Map = jRoot.Get("Reformationstag")
Dim datum As String = feiertag.Get("datum")
Dim hinweis As String = feiertag.Get("hinweis")

Dim feiertag As Map = jRoot.Get("1. Weihnachtstag")
Dim datum As String = feiertag.Get("datum")
Dim hinweis As String = feiertag.Get("hinweis")

Dim feiertag As Map = jRoot.Get("Heilige Drei Könige")
Dim datum As String = feiertag.Get("datum")
Dim hinweis As String = feiertag.Get("hinweis")

Dim feiertag As Map = jRoot.Get("Neujahrstag")
Dim datum As String = feiertag.Get("datum")
Dim hinweis As String = feiertag.Get("hinweis")

Dim feiertag As Map = jRoot.Get("Gründonnerstag")
Dim datum As String = feiertag.Get("datum")
Dim hinweis As String = feiertag.Get("hinweis")

Dim feiertag As Map = jRoot.Get("Fronleichnam")
Dim datum As String = feiertag.Get("datum")
Dim hinweis As String = feiertag.Get("hinweis")
 
Upvote 0

FrankDev

Active Member
Licensed User
Longtime User
yes... that is the result of Json Tree.

but with the output I MUST know all the days.
If a new one is added, it doesn't work anymore...

wouldn't that have made more sense?
[{'name':'christmasholiday1', 'date':'25.12.2023','note':''},{'name':'christmasholiday2', 'date':'26.12.2023','note':''}]

B4X:
Dim parser As JSONParser
parser.Initialize(j.GetString)
Dim jRoot As Map = parser.NextObject
For i = 0 To jRoot.Size - 1
     Log("Key: " & jRoot.GetKeyAt(i))
     Log("Value: " & jRoot.GetValueAt(i))
     ......     
Next

This seems to make sense to me!
 
Last edited:
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
there is a possibility to read the number of keys (days). (for a disc) and then get a list of the keys (holiday days).
B4X:
    Dim parser As JSONParser
    parser.Initialize($"{"Neujahrstag":{"datum":"2023-01-01","hinweis":""},"Heilige Drei K\u00f6nige":{"datum":"2023-01-06","hinweis":""},"Gr\u00fcndonnerstag":{"datum":"2023-04-06","hinweis":"Gem\u00e4\u00df \u00a7 4 Abs. 3 des Feiertagsgesetzes von Baden-W\u00fcrttemberg[10] haben Sch\u00fcler am Gr\u00fcndonnerstag und am Reformationstag schulfrei. In der Regel legt das Kultusministerium die Ferientermine so fest, dass diese beiden Tage in die Osterferien bzw. in die Herbstferien fallen."},"Karfreitag":{"datum":"2023-04-07","hinweis":""},"Ostermontag":{"datum":"2023-04-10","hinweis":""},"Tag der Arbeit":{"datum":"2023-05-01","hinweis":""},"Christi Himmelfahrt":{"datum":"2023-05-18","hinweis":""},"Pfingstmontag":{"datum":"2023-05-29","hinweis":""},"Fronleichnam":{"datum":"2023-06-08","hinweis":""},"Tag der Deutschen Einheit":{"datum":"2023-10-03","hinweis":""},"Reformationstag":{"datum":"2023-10-31","hinweis":"Gem\u00e4\u00df \u00a7 4 Abs. 3 des Feiertagsgesetzes von Baden-W\u00fcrttemberg[10] haben Sch\u00fcler am Gr\u00fcndonnerstag und am Reformationstag schulfrei. In der Regel legt das Kultusministerium die Ferientermine so fest, dass diese beiden Tage in die Osterferien bzw. in die Herbstferien fallen."},"Allerheiligen":{"datum":"2023-11-01","hinweis":""},"1. Weihnachtstag":{"datum":"2023-12-25","hinweis":""},"2. Weihnachtstag":{"datum":"2023-12-26","hinweis":""}}"$)
    Dim jRoot As Map = parser.NextObject
    
    For Each k As String In jRoot.Keys
        
        Dim YourFeiertag As Map = jRoot.Get(k)
        Log(k)
        Log(YourFeiertag.Get("datum"))
        Log(YourFeiertag.Get("hinweis"))
        
    Next
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
yes... that is the result of Json Tree.
NO. I changed the resulting code for you so that the code works.
but with the output I MUST know all the days.
YOU CAN know this with the code i posted! What is not clear?
wouldn't that have made more sense?
Contact the API-Author and ask him to change the results returning. I am not responsible for the json you get from the Api.

I just adapted the code to be able to parse the result correctly.
 
Upvote 0

FrankDev

Active Member
Licensed User
Longtime User
B4X:
Dim parser As JSONParser
parser.Initialize(j.GetString)
Dim jRoot As Map = parser.NextObject
For i = 0 To jRoot.Size - 1
    Log("Key: " & jRoot.GetKeyAt(i))
    Log("Value: " & jRoot.GetValueAt(i))
        
    ...
Next
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
See point 3
 
Upvote 0
Top