The given key was not present in the dictionary.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
Source Error:
Line 12: dic.Add(item.Split(":"c)(0), item.Split(":"c)(1))
Line 13: Next
Line 14: Dim customerId As String = dic("CustomerId")
Line 15: Dim comments As String = dic("Comments")
Line 16: Dim clas As String = dic("Class")
Source File: D:\Generic_Handler_JSON\simplesender.aspx.vb Line: 14
This is my code
Dim json As String = New System.Net.WebClient().DownloadString("http://192.168.1.239/Generic_Handler_JSON/HandlerVBEvents.ashx")
Dim count As String = json.Split(":"c)(1).Replace("}", "")
' Dim json As String = File.ReadAllText(Server.MapPath("~/JSon.txt"))
Dim values As String() = json.Replace("""[{", "").Replace("}]""", "").Replace("""", "").Split(","c)
Dim dic As Dictionary(Of String, String) = New Dictionary(Of String, String)()
For Each item In values
dic.Add(item.Split(":"c)(0), item.Split(":"c)(1))
Next
Dim customerId As String = dic("CustomerId")
Dim comments As String = dic("Comments")
Dim clas As String = dic("Class")
This is the Json Data i am trying to get
"[{""CustomerId"":""05-00001"",""Comments"":""Jana Sports Day Please Come Early"",""Dates"":""\/Date(1543525200000)\/"",""Status"":null,""Class"":""P1"",""Stream"":null,""Term"":null,""Years"":null}]"