可能重复:
在 C# 中解析 JSON
我正在尝试使用 JSON.NET 在 ASP.NET (4.5) Web 应用程序中反序列化来自 openlibrary.org 的 JSON 字符串。
我的目标是能够从单个 .Net 对象中读取以下 5 个属性。
我的示例 JSON 是:
{"ISBN:0201558025":
{
"bib_key": "ISBN:0201558025",
"preview": "noview",
"thumbnail_url": "http://covers.openlibrary.org/b/id/135182-S.jpg",
"preview_url": "http://openlibrary.org/books/OL1429049M/Concrete_mathematics",
"info_url": "http://openlibrary.org/books/OL1429049M/Concrete_mathematics"
}
}
我可以让它在没有第一行的情况下正常工作,但我在试图弄清楚我应该如何构建我的课程时有点迷失了。
我是 JSON 新手,几年没玩过 C#/VB.NET,所以非常迷茫。
更新
我有以下代码:
Dim url = "http://openlibrary.org/api/books?bibkeys=ISBN:0201558025&format=json"
Dim webClient = New System.Net.WebClient
Dim json = webClient.DownloadString(url)
Dim book As Book = JsonConvert.DeserializeObject(Of Book)(json)
和课本:
Public Class Book
Public bib_key As String
Public preview As String
Public preview_url As String
Public info_url As String
End Class
然而,书变成了空的。