Skip to content
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

How can I send a stringified JSON using this library? #361

Closed
fredlemieux opened this issue Aug 14, 2018 · 2 comments
Closed

How can I send a stringified JSON using this library? #361

fredlemieux opened this issue Aug 14, 2018 · 2 comments

Comments

@fredlemieux
Copy link

Hi there,
Great VBA tool by the way. But I have one question, how can I post data in a stringified JSON in the format?

strRequest = """{\""LastName\"":\""Jones\"",\""firstName\"":\""Bubba\""}"""

rather than using dictionaries? The following curl request works, but when I try using VBA to send data to firebase the data is not parse.

curl -X PUT -d "{\"LastName\":\"Jones\",\"firstName\":\"Bubba\"}" https://<database-name>.firebaseio.com/rest/test/.json

Using you library and the following works, the data is parsed in Firebase:


Sub test()

Dim Body As New Dictionary
Body.Add "mType", "OPEN_SYSTEM_TRADE"
Body.Add "systemOwnerId", 10

Dim strURL As String: strURL = "https://<database-name>.firebaseio.com/rest/test/whatwhat/.json"
    

Dim Client As New WebClient
Dim Response As WebResponse
Set Response = Client.PostJson(strURL, Body)

ActiveSheet.Range("A1").Value = Response.Content

End Sub

Thanks for your hard work and sharing this.

@zgrose
Copy link

zgrose commented Aug 14, 2018

The \ escape code for the command line isn't need in VBA.

To create a string variable to represent the JSON {"LastName":"Jones","firstName":"Bubba"} in VBA you code that as

strRequest = "{""LastName"":""Jones"",""firstName"":""Bubba""}"

For every double quote within the JSON, you escape that with a second double quote; and then a pair of double quotes to enclose your string variable.

@fredlemieux
Copy link
Author

Fantastic, that works a treat! Thank you so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants