【发布时间】:2022-12-20 00:05:16
【问题描述】:
如何使用 Newtonsoft.Json C# 反序列化此 JSON?
{
"catalog": {
"book": [
{
"id": "1",
"author": "Autho1",
"title": "GDB",
"genre": "Kl",
"price": "15",
"publish_date": "1999-09-02",
"description": "desc about book"
},
{
"id": "2",
"author": "Lil",
"title": "JS",
"genre": "DS",
"price": "3.6",
"publish_date": "1999-09-02",
"description": "desc 2."
}
]
}
}
我需要将 JSON 反序列化为一个结构,但最后我有 book = nil
【问题讨论】:
-
你试过什么了?
-
newtonsoft.com/json 的首页提供了一个很好的序列化和反序列化示例。
-
为什么结构? Class 更适合这些。
-
步骤 1. 创建一个名为
Book的类,其中包含所有必要的属性。第 2 步。使用Book数组创建一个名为Catalog的类,第 3 步。反序列化为类型Catalog。