M Martincg Member Licensed User Longtime User Sep 29, 2019 #1 If read arrays of JSON strings like this { "value":17, "date":"2019-09-29 20:30:00" } Not all will have both entries. How do I find out which entries are included?
If read arrays of JSON strings like this { "value":17, "date":"2019-09-29 20:30:00" } Not all will have both entries. How do I find out which entries are included?
M Martincg Member Licensed User Longtime User Sep 29, 2019 #2 OK, I've discovered Map.Keys so all I need is Code: Copy For Each mKey As String In MyMap.Keys if mKey = "value" then newVal = MyMap.Get("Value") Next Upvote 0
OK, I've discovered Map.Keys so all I need is Code: Copy For Each mKey As String In MyMap.Keys if mKey = "value" then newVal = MyMap.Get("Value") Next
Erel B4X founder Staff member Licensed User Longtime User Oct 1, 2019 #3 There are several mistakes in this code: 1. The case is important. It should be MyMap.Get("value") 2. If you are interested in a specific key and you are not sure whether it exists or not then you should check it with ContainsKey: Code: Copy If MyMap.ContainsKey("value") Then Dim value As Int = MyMap.Get("value") End If Another option if you want to be more sophisticated: Code: Copy newVal = MyMap.GetDefault("value", newVal) Last edited: Oct 2, 2019 Upvote 0
There are several mistakes in this code: 1. The case is important. It should be MyMap.Get("value") 2. If you are interested in a specific key and you are not sure whether it exists or not then you should check it with ContainsKey: Code: Copy If MyMap.ContainsKey("value") Then Dim value As Int = MyMap.Get("value") End If Another option if you want to be more sophisticated: Code: Copy newVal = MyMap.GetDefault("value", newVal)
M Martincg Member Licensed User Longtime User Oct 1, 2019 #4 Thanks Erel, I will use your suggestions. I probably should have found that myself, but although I did one project a few years ago I am really a newbie and I can only take in so much at a time. Upvote 0
Thanks Erel, I will use your suggestions. I probably should have found that myself, but although I did one project a few years ago I am really a newbie and I can only take in so much at a time.