我创建了一个多维数组..它存储数据库中的表行值..我需要将数组元素存储为 json 格式,并且应该单独显示数组元素(即,与数据库表中的行一样)。我的代码在这里..但它以这样的 json 格式显示所有数据。:
{"question":"6"}{"question":"mother?"}{"question":"fghh"}{"question":"bbb"}{"question":"qwe"}{"question":"wer"}{"question":"5"}{"question":"colg?"}{"question":"sdf"}{"question":"scf"}{"question":"aaa"}{"question":"dfdf"}
我的代码在这里:
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);
}
}
我怎样才能像在数据库表中那样逐行显示它?请帮忙 ?我需要这样的输出:
{"question" : "6" "mother?" "bbb" "fghhh" "bbb" "qwe" "wer"}{"question" : "5" "colg" "sdf" "scf" "aaa" "ddd" "hjk"}