I have created a multi dimensional array.. which stores the table rows values from database..I need to store the array elements into json format,and should display the array elements seperately(ie,row wise as in the data base table). my code is here..but it displays all the data in json format like this. :
{"question":"6"}{"question":"mother?"}{"question":"fghh"}{"question":"bbb"}{"question":"qwe"}{"question":"wer"}{"question":"5"}{"question":"colg?"}{"question":"sdf"}{"question":"scf"}{"question":"aaa"}{"question":"dfdf"}
my code is here :
SqlDataAdapter da = new SqlDataAdapter("select question_num,q_text,answer1_text,answer2_text,answer3_text,answer4_text from question_bank_details where question_num in (select top 2 question_num from question_bank_details order by newid())", con5);
DataTable dt = new DataTable();
da.Fill(dt);
int i; int j;
string[,] array_questions = new string[dt.Rows.Count, dt.Columns.Count];
for (i = 0; i < dt.Rows.Count; i++)
{
for (j = 0; j < dt.Columns.Count; j++)
{
array_questions[i, j] = dt.Rows[i][j].ToString();
//Response.Write(array_questions[i, j]);
}
}
foreach (string question_row in array_questions)
{
var ques = new { question = question_row };
JavaScriptSerializer js = new JavaScriptSerializer();
// string json = js.Serialize(question_row);
string json = js.Serialize(ques);
Response.ContentType = "application/json";
Response.Write(json);
}
}
how can i display it row wise as in the database table ? please help ? I need the output like this :
{"question" : "6" "mother?" "bbb" "fghhh" "bbb" "qwe" "wer"}{"question" : "5" "colg" "sdf" "scf" "aaa" "ddd" "hjk"}