I have a json data like below and i need to parse through it. I tried the below code and getting TypeMismatchException. Could you please help
Dim jsonData As Text = “{“1”:{“FirstName”:“Abdul”,“LastName”:“Mcconnell”,“City”:“Colorado Springs”,“State”:“CO”,“Zip”:“80935”}, _
“2”:{“FirstName”:“Abel”,“LastName”:“Alexander”,“City”:“Arcadia”,“State”:“IA”,“Zip”:“51430”}, _
“3”:{“FirstName”:“Addison”,“LastName”:“Gallegos”,“City”:“Altamont”,“State”:“MO”,“Zip”:“64620”}}”
Dim json() As Auto
json = Xojo.Data.ParseJSON(jsonData) // Error Here ---- “TypeMismatchException”
For Each a As Xojo.Core.Dictionary In json
CustomerList.AddRow(a.Value(“ID”), a.Value(“FirstName”), a.Value(“LastName”))
Next
Your jsondata is invalid…
this is the right format for json
{
"1" : {
"FirstName" : "Abdul",
"LastName" : "Mcconnell",
"City" : "Colorado Springs",
"State" : "CO",
"Zip" : "80935"
},
"2" : {
"FirstName" : "Abel",
"LastName" : "Alexander",
"City" : "Arcadia",
"State" : "IA",
"Zip" : "51430"
},
"3" : {
"FirstName" : "Addison",
"LastName" : "Gallegos",
"City" : "Altamont",
"State" : "MO",
"Zip" : "64620"
}
}
Your json have arrays so you must go trough each one…take a look here with the same problem i have.
Parse json
Clarification: these aren’t arrays, they are “objects”, or the JSON equivalent of Xojo Dictionaries. If those underscores appear in the original data, Loannis is correct, the data is invalid.
Thanks all for the reply. I need to parse through each dictionaryentry and got success.