Skip to content

Quotes in keys are not escaped #100

Open
@ramyaprabhakar

Description

@ramyaprabhakar

Hi,
I am running into a problem I have no idea how to tackle.I need to construct a Json which looks like this to be passed as a request to get the sessionId as response:
{ "instruction":"login", "sessionId" : 0, "json": { ""user"":""xxxx"", ""password"":""yyyy"" } }

I'm currently passing the inner Json as Dictionary and collection parameters and then adding them to the request, but the request doesnt go in the above mentioned format whereas this is how its sent:
"{"instruction":"login","sessionId":0,"json":"[{"user":"xxxx"},{"password":"yyyy"}]"}"

My code:


Function QuerySpa() As WebResponse
Dim Client As New WebClient
Dim Request As New WebRequest
Client.BaseUrl = "http://localhost:8080/spa/api/login"

Dim c3 As Collection
Dim j3 As Dictionary
Dim j4 As Dictionary
Set c3 = New Collection
Set j3 = New Dictionary
Set j4 = New Dictionary

j3.Add "user", "xxxx"
j4.Add "password", "yyyy"
c3.Add j3
c3.Add j4

Request.Method = WebMethod.HttpPost
Request.ResponseFormat = WebFormat.JSON
'Request.Body = JsonString
Request.AddBodyParameter "instruction", "login"
Request.AddBodyParameter "sessionId", 0
Request.AddBodyParameter "json", JsonConverter.ConvertToJson(c3)

Set QuerySpa = Client.Execute(Request)

End Function


What is the best way to build the innerJson, If given as a string, then it is adding many //s and ""s
which are very difficult to handle. Your help would be much appreciated.

Thanks in Advance
Ramya

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions