Closed sunkaifei closed 3 months ago
The current solution is
// 自定义过滤器函数
pub fn to_json_filter(value: &Value) -> Result<Value, Error> {
// 处理输入的 value,假设输入是一个字符串
let json_str = value.as_str().unwrap_or("");
match serde_json::from_str::<Value>(json_str) {
Ok(json_value) => {
Ok(json_value)
},
Err(err) => {
log::error!("Error parsing JSON: {}", err);
Ok(Value::from_safe_string("Json标签解析失败".to_string()))
},
}
}
A custom JSON parsing filter is most likely the right solution. Another option would be to parse the data before it's passed to the template.
The fields stored in my database are JSON strings, and I want to convert this field directly into a variable on the template page, and then output each content in JSON through this variable, or is there any other way to directly output it?