免去复杂的引用 一步到位
DataTable dt = new DataTable();
dt = db.getDataSet(sql).Tables[0];
if (dt == null || dt.Rows.Count < 1)
{
// 如果DataTable为空
}
string strjson = "[";
for (int i = 0; i < dt.Rows.Count; i++)
{
strjson += "{"CODE"" + ":" + """ + dt.Rows[i].ItemArray[0] + """ + "," + ""NAME"" + ":" + """ + dt.Rows[i].ItemArray[1] + """ + ","
+ ""CODE"" +":"+ """+ dt.Rows[i].ItemArray[2] + """ + "," + ""CODE"" + ":" + """+ dt.Rows[i].ItemArray[3] + """ + "," + ""CODE"" + ":" + """+ dt.Rows[i].ItemArray[4] + ""},";
}
strjson = strjson.TrimEnd(',');
strjson += "]";
strjson 出来便是JSON的格式
Key可以填自己的字段