Dictionary

  • Thread starter Thread starter Violet Madihlaba
  • Start date Start date
V

Violet Madihlaba

Guest
Hi,

I am trying to retrieve a json array in vb.net using visual studio 2010 and i am getting the "given key not found in dictionary" error. Your help will be highly appreciated

My JSON array: [{"status":1,"desc":"Successfully retrieved 5 categories..","data":[{"2":{"name":"ACCOUNTS","price":null,"image":null},"5":{"name":"DRIVER FBR","price":null,"image":null},"4":{"name":"GENERAL","price":null,"image":null},"10":{"name":"MASTER DATA","price":null,"image":null},"3":{"name":"QUERIES","price":null,"image":null}}]}]

My code:

Imports System.IO
Imports System.Net
Imports System.Web.Script.Serialization

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


Dim uriString As String = "http://1stbn.co.za/dev/api/_lkpCompanyQMCategories.php?cid=1&limi=50"
Dim uri As New Uri(uriString)

'Make HTTP Request
Dim request As HttpWebRequest = HttpWebRequest.Create(uri)
request.Method = "GET"


'Get HTTP Response
Dim response As HttpWebResponse = request.GetResponse()

'Read HTTP Response
Dim read As New StreamReader(response.GetResponseStream())
Dim raw As String = read.ReadToEnd()

Dim dic As Object = New JavaScriptSerializer().Deserialize(Of List(Of Object))(raw)


For Each item As Object In dic
TextBox1.Text = item("data").ToString + "-" + item("data").ToString + vbNewLine
Console.WriteLine(item.ToString)

'TextBox1.Text = item("data").ToString & vbCrLf
'TextBox1.Text = item("status").ToString & vbCrLf
'TextBox1.Text = item("desc").ToString & vbCrLf
Next

End Sub

End Class

Continue reading...
 
Back
Top