For smart Primates & ROBOTS (oh and ALIENS ).

Blogroll

Wednesday, September 03, 2014

Parse single line JSON data in C#

Parse Single line JSON data in C# without objects

If you have received this JSON data string as listed below:
[‘aa’,’bb’,’cc’ ,’dd’,’ee’ ,’ff’,’gg’ ,’hh’,’ii’ ,’jj’,’kk’ ,’ll’,’mm’ ,’nn’,’oo’]

This is the array of JSON, you can see there are no Object data in that JSON string.
So, how you retrieve this JSON data in C#?
I have used JSON.Net from Newtonsoft.Json. it is a free library so you can download it from their site.






using Newtonsoft.Json.Linq;

String jsonData=”[‘aa’,’bb’,’cc’ ,’dd’,’ee’ ,’ff’,’gg’ ,’hh’,’ii’ ,’jj’,’kk’ ,’ll’,’mm’ ,’nn’,’oo’]”;
JArray names= JArray.Parse(jsonData);
//By foreach loop
foreach (Object nm in names){
    MessageBox.show(nm.toString());
}
// By For loop
for (int j=0; i< names.Count;j++) {
String nm = names [j].ToString();
MessageBox.show(nm.toString());
}

Share:

0 comments:

Post a Comment

Multiple attribute passing in querySelectorAll

Multiple attribute passing in querySelectorAll     Here I am demonstrating code to how to pass multiple attributes in querySelectorAll. <...

Ads Inside Post

Powered by Blogger.

Arsip

Blog Archive