Sandy Bhardwaj

Sandy Bhardwaj

  • 1.4k
  • 339
  • 2.6k

How can i store Object Json in Array Json with Array name ?

Sep 15 2017 8:17 AM
//This is my code and i want to pass api with array name please give me the answer
 
protected void Page_Load(object sender, EventArgs e)
{
IsTrue = 0;
if (string.IsNullOrEmpty(Request.QueryString["Username"]) == false && string.IsNullOrEmpty(Request.QueryString["Password"]) == false)
{
IsTrue = 1;
}
if (IsTrue > 0)
{
DataTable dt = new DataTable();
UserName = Request.QueryString["UserName"];
Password = Request.QueryString["Password"];
con.Open();
dt.Load(new SqlCommand("select Top 10 Memberid,MemberName from PartyMaster Order by msrno", con).ExecuteReader());
con.Close();
System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
Dictionary<string, object> row = default(Dictionary<string, object>);
foreach (DataRow dr in dt.Rows)
{
row = new Dictionary<string, object>();
foreach (DataColumn col in dt.Columns)
{
row.Add(col.ColumnName, dr[col]);
}
rows.Add(row);
}


//string Mystr = serializer.Serialize(rows);

string Mystr = serializer.Serialize(rows);



Response.ContentType = "application/json"; //JSON Text output
Response.Write(Mystr);


}