Desrializing json arrays in ASP.NET

Jan 25, 2011
Reaction score
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",

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)
Dim oResponse As HttpWebResponse = request.GetResponse()
Dim reader As New StreamReader(oResponse.GetResponseStream())
Dim tmp As String = reader.ReadToEnd()
' 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()
Return sAddress
End Get
Set(ByVal value)
sAddress = value
End Set
End Property
<DataMember()> _
Public Property errors()
Return sErrors
End Get
Set(ByVal value)
sErrors = value
End Set
End Property
<DataMember()> _
Public Property extras()
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 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.


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question