error: Illegal characters in path. (JsonArray)

WebSpider 76 Reputation points
2021-08-13T07:36:19.247+00:00

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
VB
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
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 114.7K Reputation points
    2021-08-13T07:50:48.247+00:00

    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
    
    0 comments No comments

0 additional answers

Sort by: Most helpful