views:

546

answers:

2

I'm trying to consume a web service in VB6. The service (which I control) currently can return a SOAP/XML message or JSON. I'm having a really difficult time figuring out if VB6's SOAP type (version 1) can handle a returned object (as opposed to simple types like string, int, etc.). So far I can't figure out what I need to do to get VB6 to play with returned objects.

So I thought I might serialize the response in the web service as a JSON string. Does a JSON parser exist for VB6?

+3  A: 

Check out JSON.org for an up-to-date list (see bottom of main page) of JSON parsers in many different languages. As of the time of this writing, you'll see a link to two different JSON parsers there:

  • VB-JSON

    • When I tried to download the zip file, Windows said the data was corrupt. However, I was able to use 7-zip to pull the files out. It turns out that the main "folder" in the zip file isn't recognized as a folder by Windows, by 7-zip can see the contents of that main "folder," so you can open that up and then extract the files accordingly.
    • The actual syntax for this VB JSON library is really simple:

      Dim p As Object
      Set p = JSON.parse(strFormattedJSON)
      
      
      'Print the text of a nested property '
      Debug.Print p.Item("AddressClassification").Item("Description")
      
      
      'Print the text of a property within an array '
      Debug.Print p.Item("Candidates")(4).Item("ZipCode")
      
    • Note: VBJSON code is actually based on a google code project. However, VBJSON promises several bug fixes from the original version.
  • PW.JSON
    • This is actually a library for VB.NET, so I didn't spend much time looking into it.
Ben McCormack
+1  A: 

I would suggest using a .Net component. You can use .Net components from VB6 via Interop - here's a tutorial. My guess is that .Net components will be more reliable and better supported than anything produced for VB6.

There are components in the Microsoft .Net framework like DataContractJsonSerializer or JavaScriptSerializer. You could also use third party libraries like JSON.NET.

MarkJ
@MarkJ Thanks for the suggestion. You bring up a good point that .NET components will be better supported than anything in VB6. That is certainly the case. However (and I could be wrong here), JSON is simple enough that even VB6 shouldn't have a problem with it. The VB-JSON code that I mentioned has so far worked really well.
Ben McCormack
@Ben JSON is simple, but you say the google code project used as a starting point still managed to have several bugs, so it's still possible to get it wrong.
MarkJ