「Datatable」、「Datatable」コンテンツidstudent、avg、firstname、namecourse、およびdateを返すコードがあります。この「Datatable」コンテンツはさらに行です。
DataTable row = mn.selectProgram("programStudent", attributes);
JsonTrans responce = new JsonTrans();
responce.Convert(row);
//if (row.Rows.Count != 0)
//{
// foreach (DataRow result in row.Rows)
// {
// string idstudent = result["id"].ToString();
// string avgstudent = result["AVG"].ToString();
// string firstname = result["fname"].ToString();
// string date = result["date"].ToString();
// string namecourse = result["name"].ToString();
// }
//}
私は試します:
public string Convert(DataTable row)
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
JsonWriter jsonWriter = new JsonTextWriter(sw);
jsonWriter.Formatting = Formatting.Indented;
jsonWriter.WriteStartArray();
if (row.Rows.Count != 0)
{
foreach (DataRow result in row.Rows)
{
jsonWriter.WriteStartObject();
string idstudent = result["id"].ToString();
jsonWriter.WritePropertyName("id");
jsonWriter.WriteValue(idstudent);
jsonWriter.WriteEndObject();
}
}
jsonWriter.WriteEndArray();
jsonWriter.Close();
sw.Close();
この行を次のようにjsonに変換するにはどうすればよいですか:
[ {idstudent:"value" ,avg :"value" , avg : "value",firstname :"value"}
{idstudent:"value" ,avg :"value" , avg : "value",firstname :"value"}
{idstudent:"value" ,avg :"value" , avg : "value",firstname :"value"} ]