let url = "mysql://root:123456@localhost:3307/shop";
let pool = Pool::new(url)?;
let mut conn = pool.get_conn()?;
let result: Option<Row> = conn.query_first("select * from book").expect("query list err");
if let Some(row) = result {
// Now you need to convert the query result into a json string
let mut json_obj = json!({});
for col in row.columns_ref() {
let col_key = col.name_str().to_string();
let col_val = &row[col.name_str().as_ref()];
println!("-----777----{}----{:?}----------", col_key, col_val,);
// Assemble as a json object,Calling col_val like this results in an error
json_obj[col_key] = json!(col_val);
}
// Convert the json object to a json string, which makes it easier to assign values to the structure
let res = serde_json::to_string_pretty(&json_obj).unwrap();
}
The effect of printing out is as follows, you can already read the data after the query, but the data of 'col_val' always has' Bytes("xxx") 'wrapped, how to take out the values in Bytes, such as:' Bytes("0") 'into' 0"
-----777----err_info----Null----------
-----777----system_id----Bytes("0")----------
-----777----create_at----Bytes("17110115..")----------