The following code gets a TypeMisMatchException on the jsonReg=json.Value(“Complete”) Line. Its says ‘Expected object but got Type Auto’.
Any idea why. Very Similar code works without error processing a different set of JSON Data.
[code] dim jsonReg as Dictionary
dim intCount as Integer
intCount=1
jsonReg=json.Value(“Complete”)
For Each entry as DictionaryEntry in jsonReg
Dim regDict As Dictionary = entry.Value
App.Reg.AC=regDict.Value("cy")
App.RC=regDict.Value("cy")
AppReg.ClD=regDict.Value("cd")
App.ClID=regDict.Value("cd")
App.Reg.MT=regDict.Value("oc")
App.Reg.Dt=regDict.Value("dt")
Next[/code]
Forgot json is a dictionary of already processed data using PARSEJSON passed in to this method.
Here is an example of the JSON its parsing
{"Complete":[{"dt":"u999","cd":"C16","cc":"GA","cy":"2615","oc":"TT 1"}]}
Have you tried converting directly the Json to a Dictionary ?
Dim jsonReg As Xojo.Core.Dictionary
jsonReg = Xojo.Data.ParseJSON(jsonText)
That is what the dictionary json is. It was done in the method that called this one.
[quote=298883:@Michel Bujardet]Have you tried converting directly the Json to a Dictionary ?
Dim jsonReg As Xojo.Core.Dictionary
jsonReg = Xojo.Data.ParseJSON(jsonText)
[/quote]
Found a solution When I looked at the contents of the dictionary in the debugger the data was typed Auto. So I loaded it into an Array Typed Auto and then it let me access the data without error.
dim regArray() as Auto=json.Value("Complete")
For Each regDict as Dictionary in regArray
App.Reg.AC=regDict.Value("cy")
App.RC=regDict.Value("cy")
App.Reg.ClID=regDict.Value("cd")
App.ClockID=regDict.Value("cd")
App.Reg.MT=regDict.Value("oc")
App.Reg.Dt=regDict.Value("dt")
Next