json - 是否可以使用 serde_json 反序列化看起来像 JSON(但不是)的数据?

标签 json rust serde

我很难反序列化(使用 Rust 的 serdeserde_json v1.0)我收到的以下 JSON:

{
    ["string content"]
}

对象的数组不是由键标识的,因此以下内容不起作用:

#[derive(Deserialize)]
struct Data {
    key: Vec<String>
}

我也尝试在 key 字段上使用 #[serde(flatten)] 但我收到错误:

can only flatten structs and maps (got a sequence)

我收到的数据看起来不像是有效的 JSON。是否仍然可以使用 serde_json

最佳答案

您显示的输入不是有效的 JSON。您将无法使用 serde_json 反序列化该输入,因为 serde_json 只接受 JSON。

如果您发现数据的预期格式,请考虑使用(或编写)专用于该特定格式的 Rust 库。

关于json - 是否可以使用 serde_json 反序列化看起来像 JSON(但不是)的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53916828/

相关文章:

rust - 使用 `serde_yaml` 反序列化多个文档

php 数组转换成 javascript 数组 document.write javascript_array

python - 在 Python 中序列化/反序列化类对象的最佳方法是什么?

javascript - 如何将 JSON 字符串附加到 HTML 预标记?

shell - 如何在同时传送stdio的同时模拟TTY?

json - Serde反序列化为多个结构之一?

javascript - 使用plotly.js 从 JSON 构建绘图

c++ - rust-bindgen 绑定(bind)引发 SIGSEGV

c - Rust ffi + wasm (yew -> cargo 网络启动) -> fatal error : 'math.h' file not found

rust - 使用空对象作为值反序列化映射