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());
}
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());
}
0 comments:
Post a Comment