VBA-tools / VBA-Web

VBA-Web: Connect VBA, Excel, Access, and Office for Windows and Mac to web services and the web
http://vba-tools.github.io/VBA-Web/
MIT License
2.01k stars 494 forks source link

Issue with accessing json value of key in WebHelpers.ParseJson #173

Closed mithunmanohar closed 8 years ago

mithunmanohar commented 8 years ago

Hi, I am trying to parse a json response from web service like below. Dim Json As Object Set Json = WebHelpers.ParseJson ("{""a"":123,""b"":[1,2,3,4],""c"":{""d"":456}}")

I would like to print out the value of key 'c' ie {""d"":456}.

But when I try to access it like MsgBox Json("c"), I am getting an argument not optional error. I cannot specify the key to get the elements as the key in response varies from time to time.

It would be great if any body can help me figure out how to get this done.

timhall commented 8 years ago

Hi @mithunmanohar79, ParseJson parses recursively so {"d":456} has been parsed into a Dictionary and you can use Keys/Items to get the keys/values out of it. If you want to print the whole Dictionary out, you can use MsgBox WebHelpers.ConvertToJson(Json("c")) which converts the Dictionary back into a json object string.

mithunmanohar commented 8 years ago

Thanks @timhall for your quick reply !