I'm trying to catch the error message from a WebRequest
that returns a 400 Bad Request message when the user enters bad info. I want to display the message to the screen and according to this, I should be able to deserialize the string containing the JSON and then access the error message like this:
Try
'My web request is here
Catch ex As WebException
Using resp As HttpWebResponse = ex.Response
Using data As Stream = resp.GetResponseStream()
Using reader = New StreamReader(data)
Dim bodyContent As String = reader.ReadToEnd()
Dim bodyObj = JsonConvert.DeserializeObject(bodyContent)
lblMyLabel.Text = bodyObj.error.message
End Using
End Using
End Using
End Try
However, I'm getting an error message saying:
Public member 'error' on type 'JObject' not found.
How can I correct this issue?