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.Read JSON string Array and assign value to string variable in C# and VB.Net<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[] values = 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 values) { dic.Add(item.Split(&#39;:&#39;)[0], item.Split(&#39;:&#39;)[1]); } string customerId = dic[&#34;CustomerId&#34;]; string comments = dic[&#34;Comments&#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;); }</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 values 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 values 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;) 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;) End Sub</pre> <p><span style="text-decoration: underline;"><strong>Output</strong></span></p> <p>CustomerId is <strong>05-00001</strong></p> <p>comments is <strong>Jana Sports Day Please Come Early </strong></p> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/170123/Read-JSON-string-Array-and-assign-value-to-string-variable-in-C-and-VBNet/https://www.aspforums.net:443/Threads/170123/Read-JSON-string-Array-and-assign-value-to-string-variable-in-C-and-VBNet/Tue, 04 Dec 2018 05:18:42 GMT