ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary<p>I will get back soon.</p>https://www.aspforums.net:443/Threads/117065/SystemCollectionsGenericKeyNotFoundException-The-given-key-was-not-present-in-the-dictionary/https://www.aspforums.net:443/Threads/117065/SystemCollectionsGenericKeyNotFoundException-The-given-key-was-not-present-in-the-dictionary/Sun, 09 Dec 2018 23:08:48 GMTSystem.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary<p>Hey <a class="username" rel="makumbi">makumbi</a>,</p> <p>Please refer below sample.</p> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.IO;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.IO</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { string json = File.ReadAllText(Server.MapPath(&#34;~/JSon.txt&#34;)); string[] count = json.Replace(&#34;\&#34;[{&#34;, &#34;&#34;).Replace(&#34;}]\&#34;&#34;, &#34;&#34;).Replace(&#34;\&#34;&#34;, &#34;&#34;).Split(&#39;,&#39;); ; Dictionary&lt;string, string&gt; dic = new Dictionary&lt;string, string&gt;(); foreach (var item in count) { dic.Add(item.Split(&#39;:&#39;)[0], item.Split(&#39;:&#39;)[1]); } string customerId = dic[&#34;CustomerId&#34;]; string comments = dic[&#34;Comments&#34;]; string clas = dic[&#34;Class&#34;]; Response.Write(&#34;CustomerId is &lt;b&gt;&#34; + customerId + &#34;&lt;/b&gt;&lt;br/&gt;comments is &lt;b&gt;&#34; + comments + &#34;&lt;/b&gt;&#34; + &#34;&lt;/b&gt;&lt;br/&gt;comments is &lt;b&gt;&#34; + clas + &#34;&lt;/b&gt;&#34;); }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load Dim json As String = File.ReadAllText(Server.MapPath(&#34;~/JSon.txt&#34;)) Dim count As String() = json.Replace(&#34;&#34;&#34;[{&#34;, &#34;&#34;).Replace(&#34;}]&#34;&#34;&#34;, &#34;&#34;).Replace(&#34;&#34;&#34;&#34;, &#34;&#34;).Split(&#34;,&#34;c) Dim dic As Dictionary(Of String, String) = New Dictionary(Of String, String)() For Each item In count dic.Add(item.Split(&#34;:&#34;c)(0), item.Split(&#34;:&#34;c)(1)) Next Dim customerId As String = dic(&#34;CustomerId&#34;) Dim comments As String = dic(&#34;Comments&#34;) Dim clas As String = dic(&#34;Class&#34;) Response.Write(&#34;CustomerId is &lt;b&gt;&#34; &amp; customerId &amp; &#34;&lt;/b&gt;&lt;br/&gt;comments is &lt;b&gt;&#34; &amp; comments &amp; &#34;&lt;/b&gt;&#34; &amp; &#34;&lt;/b&gt;&lt;br/&gt;comments is &lt;b&gt;&#34; &amp; clas &amp; &#34;&lt;/b&gt;&#34;) End Sub</pre> <p><span style="text-decoration: underline;"><strong>Output</strong></span></p> <p>CustomerId is <strong>05-00001</strong> comments is <strong>Jana Sports Day Please Come Early</strong> comments is <strong>P1</strong></p>https://www.aspforums.net:443/Threads/117065/SystemCollectionsGenericKeyNotFoundException-The-given-key-was-not-present-in-the-dictionary/https://www.aspforums.net:443/Threads/117065/SystemCollectionsGenericKeyNotFoundException-The-given-key-was-not-present-in-the-dictionary/Mon, 10 Dec 2018 00:42:27 GMT