Hi
I need to get fields name from the dict to validate it
Dim dict As Xojo.Core.Dictionary = Xojo.Data.ParseJSON( Xojo.Core.TextEncoding.UTF8.ConvertDataToText( Content ) )
dict.value(fieldName)
but like this dict.value(“fieldName”) or dict.value(fieldName)
i try like dict.value(“fieldName”) and i have error
thanks
The key will be a string, so whether you provide it in a variable, static, or constant is up to you. But it’s case-sensitive so the key “aaa” will not match the key “Aaa”, for example, and both could exist in your JSON.
ok
i have error KeyNotFoundException
If HTTPStatus = 200 Then
Dim ff As Integer
Dim hh As Text
Dim jsonData As Text = Xojo.Core.TextEncoding.UTF8.ConvertDataToText(content)
dim d as Xojo.Core.Dictionary = Xojo.Data.ParseJSON( jsonData)
//SendYesNo=True
//dim msg as new iOSMessageBox
//msg.Buttons = Array("OK")
//msg.Title = "Info"
//msg.Message = Xojo.Core.TextEncoding.UTF8.ConvertDataToText( Content )
//msg.Show
// to fill listbox
Dim dict As Xojo.Core.Dictionary = Xojo.Data.ParseJSON( Xojo.Core.TextEncoding.UTF8.ConvertDataToText( Content ) )
If (dict.Count >=2) Then
//hh=dict.Value("DataSocioNum")
Try
hh=d.value("DataSocioNum") <<<<<< I need to see what is the fields names
ImpDataFromHost(dict)
Catch e As KeyNotFoundException
ff=e.ErrorNumber
End Try
End If
Else
// Process content for error
App.mQueryURL = “”
dim msg as new iOSMessageBox
msg.Buttons = Array("OK")
msg.Title = "Error"
msg.Message = Xojo.Core.TextEncoding.UTF8.ConvertDataToText( Content )
msg.Show
End If
End Sub
This is easier with the classic Dictionary. Any reason you chose to use the Xojo framework?
Anyway…
dim keys() as string
for each entry as Xojo.Core.DictionaryEntry in myDict
keys.Append entry.Key
next
// Now the keys are in that array
In your code, you are checking the key in d, not dict, is that what you intended?
(I recommend using descriptive names for your variables. It’s more typing, but makes for easier-to-read code.)
Finally, when posting code, please help us out by using the Code tags.
No reason i was thinking the xojo.core is more new, So what is the deferences in classic vs Xojo framework ?
thanks
The Xojo framework has been de-emphasized. The new version of Xojo has ParseJSON to a Dictionary built in.
ok
but i am using this code in IOS
Moved to iOS channel.