在 Ubuntu 上为 .NET 安装 newtonsoft-json

Install newtonsoft-json for .NET on Ubuntu

我只是想解析一些 JSON,我从 C# 中的 API 调用返回。我在 Ubuntu 上使用 .NET。为此,我尝试使用

安装 newtonsoft-json
nuget install Newtonsoft.Json

库安装成功。然而,当我 运行 程序时,出现以下错误:

error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)

这是怎么回事?如何让 .NET 识别新库?

此外,我并不是特别喜欢这个库,我只是想在 Ubuntu 上解析 .NET 中的 frikin JSON 字符串。还有其他想法吗?

此 dll 在 Mono gac 中可用。您需要添加一个新的引用,否则您会收到错误消息。如果您使用的是 corefx,则使用 dotnet restore。包裹将被加载。 check the link

我终于明白了!我只需要手动更改 package.json 文件,然后键入 dotnet restore。之后,newtonsoft-json 工作正常。

运行 终端上的此命令(这是 OpenSUSE console/terminal。但是,相同的概念适用于 Ubuntu。)。

xxxx@localhost:~/Path/To/Project>dotnet add package Newtonsoft.Json

xxxx@localhost:~/Path/To/Project>dotnet restore

这应该可以解决它。

这对我有用:

sudo apt-get install Newtonsoft.Json