-
Notifications
You must be signed in to change notification settings - Fork 585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue parsing text to json #266
Comments
The issue with your code is that you don't understand what you are getting back from ParseJson. Basically you are being returned a nested set of objects. The variable Public Sub issue266()
Const json As String = "{""error"":{""message"":""Il totale dei pagamenti non corrisponde al totale da pagare."",""validation_result"":null}}"
Dim parsed As Scripting.Dictionary
Dim error As Scripting.Dictionary
Dim key As Variant
Dim item As Variant
Set parsed = JsonConverter.ParseJson(json)
For Each key In parsed.keys
If key = "error" Then
Set error = parsed.item(key)
For Each item In error.keys
Debug.Print item & " = " & VBA.IIf(VBA.IsNull(error.item(item)), "null", error.item(item))
Next item
End If
Next key
Exit Sub
End Sub which yields the following in the message = Il totale dei pagamenti non corrisponde al totale da pagare.
validation_result = null |
If you just want the response in a more readable form for logging, convert it back with 'pretty print': The value of the 'error' key pair is not a printable string; it's a reference to a Dictionary. To get the error message so that it can be reported to a higher level, you have to follow the links.
If the above solves your problem, please close the issue here. |
Hello, im trying to parse a responsetext from an http error 422, this is the string value response req.responsetext:
{"error":{"message":"Il totale dei pagamenti non corrisponde al totale da pagare.","validation_result":null}}
dim parsed ad dictionary
set parsed = jsonconverter.jsonparse(req.responsetext) and my json and debug:
Dim key As Variant
For Each key In Parsed.Keys
Debug.Print key, Parsed(key)
Next key
result error runtime 450 "Wrong number of arguments" because parsed have only "error" key but "nothing" as value and not second level.. please help me and sorry for my english...
The text was updated successfully, but these errors were encountered: