1

We have an application built in vb6 that needs a few functions to be re written in order to converse with our soon to be completed JSON API. The vb6 application previously communicating directly with one of our databases we are decommissioning.

Our API would be much happier if we could serialize query params to a string and send them in a query parameter via GET request

example: https://my_api_url.com/resource?query=stringified_json_object

vb6 does not speak JSON natively and relies on libraries to give it some assistance, I can read JSON but how can I turn it back into a string?

alilland
  • 2,039
  • 1
  • 21
  • 42
  • 1
    Can you not use the same library you are already using for reading json? – GSerg Sep 14 '17 at 20:06
  • 1
    apologize if this sounds a little bit pedantic, but "stringify JSON" doesn't makes much sense, i believe your question shall be: "how to serialize a VB6 Object in JSON format". If that sounds good to you, here is a good starting point: [JsonDump](https://gist.github.com/wqweto/9900581). Hope this helps! – deblocker Sep 15 '17 at 20:21
  • 1
    Possible duplicate of [Is There a JSON Parser for VB6 / VBA?](https://stackoverflow.com/questions/2782076/is-there-a-json-parser-for-vb6-vba) – C-Pound Guru Sep 19 '17 at 13:38

1 Answers1

0
Private Sub Receive(ByVal NewURL As String, NewData() As Byte)
    Dim xmlhttp As MSXML2.ServerXMLHTTP
    Set xmlhttp = New MSXML2.ServerXMLHTTP
    Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
    xmlhttp.Open "GET", NewURL, False

    xmlhttp.setRequestHeader "Content-Type", "application/json; charset=utf-8"
    xmlhttp.send
    NewData = xmlhttp.responseBody
    Set xmlhttp = Nothing
End Sub
Private Sub Send(ByVal NewURL As String, ByVal NewBlock As String) 
    Dim xmlhttp As MSXML2.ServerXMLHTTP

    Set xmlhttp = New MSXML2.ServerXMLHTTP
    Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
    xmlhttp.Open "PUT", NewURL, True

    xmlhttp.setRequestHeader "Content-Type", "application/json; charset=utf-8"
    xmlhttp.send ("[" & NewBlock & "]")
    Set xmlhttp = Nothing
End Sub

If you build the string in VB it will be something like this

AuxStr = AuxStr & "{"

'/----------------- CODE ------------------------------
AuxStr = AuxStr & """code"": " & """" & varCode & """"

'/------------- DESCRIPTION  --------------------------
AuxStr = AuxStr & "," & """name"": " & """" & varName & """"

AuxStr = AuxStr & "}"

another option is to get json from a text file