I send a request and the response comes back in json format. What it does is the user sends a zipcode and sends back data of that particular zipcode.
For example if the zipcode that was sent is 60622 then it send this response back
{
"addressvalidations":[{"city":"Chicago","countrycode":"US","postalcode":"60622","stateprovince":"IL"},{"city":"Wicker Park","countrycode":"US",
"postalcode":"60622","stateprovince":"IL"}],
"errors":[],
"extras":{}
}
Here is the code of what I have done so far:
Dim uri As New Uri("")// url is not shown for security reason
Dim data As String = "postalcode=" & sZipcode
If uri.Scheme = uri.UriSchemeHttps Then
Dim request As HttpWebRequest = HttpWebRequest.Create(uri)
request.Method = WebRequestMethods.Http.Post
request.ContentLength = data.Length
request.ContentType = "application/x-www-form-urlencoded"
Dim writer As New StreamWriter(request.GetRequestStream)
writer.Write(data)
writer.Close()
Dim oResponse As HttpWebResponse = request.GetResponse()
Dim reader As New StreamReader(oResponse.GetResponseStream())
Dim tmp As String = reader.ReadToEnd()
oResponse.Close()
' Response.Write(tmp)
'Return tmp
'testjson.Text = tmp
Dim js As System.Web.Script.Serialization.JavaScriptSerializer = New System.Web.Script.Serialization.JavaScriptSerializer()
'Dim test
Dim test As Location = js.Deserialize(Of Location)(tmp)
Dim test1 = test.addressvalidations
End If
<DataContract()> _
Public Class Location
Private sAddress
Private sErrors
Private sExtras
<DataMember()> _
Public Property addressvalidations()
Get
Return sAddress
End Get
Set(ByVal value)
sAddress = value
End Set
End Property
<DataMember()> _
Public Property errors()
Get
Return sErrors
End Get
Set(ByVal value)
sErrors = value
End Set
End Property
<DataMember()> _
Public Property extras()
Get
Return sExtras
End Get
Set(ByVal value)
sExtras = value
End Set
End Property
End Class
The above code works but I am having issue accessing the elements in address validations. I was wondering if there was a better, simpler way of doing accessing them like datacontractjsonserializer, or third party like json.net. Also I cannot use javascript for this cause i want to do this on the server side. Any thoughts on how this can be done?
Thanks for any suggestions.
For example if the zipcode that was sent is 60622 then it send this response back
{
"addressvalidations":[{"city":"Chicago","countrycode":"US","postalcode":"60622","stateprovince":"IL"},{"city":"Wicker Park","countrycode":"US",
"postalcode":"60622","stateprovince":"IL"}],
"errors":[],
"extras":{}
}
Here is the code of what I have done so far:
Dim uri As New Uri("")// url is not shown for security reason
Dim data As String = "postalcode=" & sZipcode
If uri.Scheme = uri.UriSchemeHttps Then
Dim request As HttpWebRequest = HttpWebRequest.Create(uri)
request.Method = WebRequestMethods.Http.Post
request.ContentLength = data.Length
request.ContentType = "application/x-www-form-urlencoded"
Dim writer As New StreamWriter(request.GetRequestStream)
writer.Write(data)
writer.Close()
Dim oResponse As HttpWebResponse = request.GetResponse()
Dim reader As New StreamReader(oResponse.GetResponseStream())
Dim tmp As String = reader.ReadToEnd()
oResponse.Close()
' Response.Write(tmp)
'Return tmp
'testjson.Text = tmp
Dim js As System.Web.Script.Serialization.JavaScriptSerializer = New System.Web.Script.Serialization.JavaScriptSerializer()
'Dim test
Dim test As Location = js.Deserialize(Of Location)(tmp)
Dim test1 = test.addressvalidations
End If
<DataContract()> _
Public Class Location
Private sAddress
Private sErrors
Private sExtras
<DataMember()> _
Public Property addressvalidations()
Get
Return sAddress
End Get
Set(ByVal value)
sAddress = value
End Set
End Property
<DataMember()> _
Public Property errors()
Get
Return sErrors
End Get
Set(ByVal value)
sErrors = value
End Set
End Property
<DataMember()> _
Public Property extras()
Get
Return sExtras
End Get
Set(ByVal value)
sExtras = value
End Set
End Property
End Class
The above code works but I am having issue accessing the elements in address validations. I was wondering if there was a better, simpler way of doing accessing them like datacontractjsonserializer, or third party like json.net. Also I cannot use javascript for this cause i want to do this on the server side. Any thoughts on how this can be done?
Thanks for any suggestions.