这适用于 Visual Studio。
它不适用于
Windows 2016 Server Core
运行 IIS 10
。Type 'JObject' is not defined.
。Dim parsejson As JObject = JObject.Parse(json)
所有进口都在那里。
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq
Bin
文件夹包含。Newtonsoft.Json.dll
文件。即使它们大小相同,Windows 也不会认为它们相同,因为 Newtonsoft.Json
被视为 .json
文件。
我认为也许使用
gacutil -i Newtonsoft.Json.dll
注册 .dll 文件可以解决该问题,但它不可注册。cache
。gacutil -l Newtonsoft.Json.dll
Invalid file or assembly name
我将此添加到
web.config
,但问题仍然相同。13.0.3.27908
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-13.0.3" newVersion="13.0.3" />
</dependentAssembly>
</assemblyBinding>
</runtime>
我想将其添加为我正在使用的代码。
(来自SO)
VB.NET 解析 JSON 子节点的代码(底部第二个代码)
我不只使用
[brackets]
{curly brackets}
。
JSON 示例
{"data":
{"id":3,"name":"true red","year":2002,"color":"#BF1932","pantone_value":"19-1664"}
,"support":
{"url":"https://reqres.in/#support-heading","text":
"To keep ReqRes free, contributions towards server costs are appreciated!"}}
我正在使用的代码。
Imports System.Net
Imports Newtonsoft.Json.Linq
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
Dim json As String = New System.Net.WebClient().DownloadString("https://reqres.in/api/products/3")
Dim parsejson As JObject = JObject.Parse(json)
Dim thename = parsejson.SelectToken("data.name").ToString()
txt1.Text = "Name Is " + thename
End Sub
End Class
我不只使用[括号]而只使用{大括号}。
我也有同样的问题。
在 IIS 中,右键单击运行脚本的文件夹。
选择:转换为应用程序。
在浏览器中刷新网站,一切都应该可以正常工作。