VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,668 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi, I got an error [Illegal characters in path.] in this line
Dim jsonString As String = (New StreamReader(responseFromServer)).ReadToEnd()
The [responseFromServer] is returned the following:
{"type":"SALES","totalFee":"14.80","Currency":"SGD"}
How can i check each item in JsonArray?
Dim WebResponse As WebResponse = WebRequest.GetResponse()
Dim httpResponse As HttpWebResponse = CType(WebResponse, HttpWebResponse)
dataStream = WebResponse.GetResponseStream()
If httpResponse.StatusCode = "200" Then
Dim reader As StreamReader = New StreamReader(dataStream)
Dim responseFromServer As String = reader.ReadToEnd()
Try
Dim jsonString As String = (New StreamReader(responseFromServer)).ReadToEnd()
Dim jsonArray As JArray = CType(JsonConvert.DeserializeObject(jsonString), JArray)
For Each item In jsonArray
If item("Currency") = "SGD" Then
//Do something
End If
Next
Catch ex As Exception
Response.Write(ex.Message)
End Try
reader.Close()
Else
Response.Write("Something went wrong.")
End If
Check this example, then integrate it:
Dim responseFromServer As String = "{""type"":""SALES"",""totalFee"":""14.80"",""Currency"":""SGD""}"
Dim jsonString = responseFromServer
Dim obj = JsonConvert.DeserializeObject(jsonString)
If obj("Currency") = "SGD" Then
' Do something
MsgBox("Something")
End If