public Users GetUserById(string _id)
{
MySqlConnection conn = new MySqlConnection(connstr);
conn.Open();
string sql = ("select * from Books where id = " + _id);
MySqlCommand cmd = new MySqlCommand(sql, conn);
MySqlDataReader reader = cmd.ExecuteReader();
Users obj = new Users();
if (reader.Read())
{
obj.id = Convert.ToInt32(reader[0]);
obj.UserName = reader[1].ToString();
}
reader.Close();
conn.Close();
return obj;
}
我正在以 Json 格式提供信息,但是
输出为:{"UserName":"John","id":1}
预期输出为:[{"UserName":"John","id":1}]
我缺少用于记录的方括号 我的代码有什么问题?