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

How to make center align child div

 How to make center align child div?   Suppose you have 2 Div tag. And want the make inner tag center <div id="d1">      ...

Ads Inside Post

Powered by Blogger.

Arsip

Blog Archive