Hello Everyone,
I need to pass an array of items to a script. Currently I call scripts which accept few values but not arrays.
When I need to call a web script and pass values I usually use the following code :
Code:
Dim client1 As New WebClient(), J As Newtonsoft.Json.JsonTextReader
Dim path As String = url & "/segments"
Dim formData As New NameValueCollection()
Dim responseBytes2 As Byte() = Nothing, output As String
formData.Add("code", "EQ")
formData.Add("name", "Equity")
Try
Dim Token, Value As String
Token = ""
responseBytes2 = client1.UploadValues(path, "POST", formData)
output = Encoding.ASCII.GetString(responseBytes2)
client1.Dispose()
J = New Json.JsonTextReader(New IO.StringReader(output))
MessageBox.Show(output)
While J.Read
If J.TokenType = Json.JsonToken.EndObject Or J.TokenType = Json.JsonToken.StartObject Then Continue While
If J.TokenType = Json.JsonToken.PropertyName Then
Token = J.Value
Else
Value = J.Value
End If
End While
J.Close()
Catch web As WebException
MessageBox.Show(web.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
The above works okay if I do not need to pass an array. Now if I have to pass an array of items then how do I do. For e.g. server accepts whats shown below:
HTML Code:
[
{
"symbol": "string",
"full_name": "string",
},
{
"symbol": "string",
"full_name": "string",
}
]
Please let me know how to do it. I use VS 2010 and .net framework 4.0.
Thank you,
GR