TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Rohit Sharma
NA
100
44.8k
How to get Json array format as below
Jun 28 2018 1:27 PM
{
"Status": 1,
"message": "",
"CityList": [{
"CityId": "1",
"CityName": "Rajkot",
"AreaList": [{
"AreaId": "1",
"AreaName": "Airport Road"
}, {
"AreaId": "2",
"AreaName": "Bus Stand"
}]
}, {
"CityId": "2",
"CityName": "Ahmedabad",
"AreaList": [{
"AreaId": "1",
"AreaName": "Airport Road"
}, {
"AreaId": "2",
"AreaName": "Bus Stand"
}]
}]
}
--------------------------------------------
I have DataTable of city and Area, how can i do the code to get as above formate,
---------------------------------
DataSet dsCS = Objbl.Fill_Grid("GetCountryandState", new string[] //Objbl.Fill_Grid("GetArea", new string[]
{
"View"
});
this.Context.Response.ContentType = "application/json; charset=utf-8";
this.Context.Response.Write(GetJSON(dsCS));
-------------------------------------------------------------------------------
public string GetJSON(DataSet ds)
{
System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
ArrayList root = new ArrayList();
List<Dictionary<string, object>> table;
Dictionary<string, object> data;
foreach (DataTable dt in ds.Tables)
{
table = new List<Dictionary<string, object>>();
foreach (DataRow dr in dt.Rows)
{
data = new Dictionary<string, object>();
foreach (DataColumn col in dt.Columns)
{
data.Add(col.ColumnName, dr[col]);
}
table.Add(data);
}
root.Add(table);
}
return serializer.Serialize(root);
}
-----------------------------------------------------------------------------
I am using this code but unable to get the above format. So please help me
Reply
Answers (
1
)
generate jwt token in C# using subscription key(Azure)
Json object converting error at the time of deserializing