CS0246未找到类型或名称空间“ Newtonsoft”

问题描述 投票:-1回答:2

在全新安装Unity3D(2018.1.1f1)之后,它先安装了VS 2017(15.7.3)。我开始了一个cs脚本,并想调试对象“ print_r”样式,因此我通过nuGet Package-Manager安装了Newtonsoft.Json 11.0.2。如果我在pakage-console中称“ Get-Package”,它向我显示

Newtonsoft.Json                     {11.0.2}                                 Assembly-CSharp  

不幸的是,当我尝试编译时,它仍然使我出错:

Schweregrad Code    Beschreibung    Projekt Datei   Zeile   Unterdrückungszustand

Fehler CS0246 Der Typoder Namespacename“ Newtonsoft” wurde nicht gefunden(使用-Direktive oder ein在Assemblyverweis中使用。 Assembly-CSharp C:\ Users \ bubu \ Documents \ Therapiefilm \ Assets \ test.cs 4 Aktiv这意味着找不到命名空间“ Newtonsoft”,或者缺少Assembly-Link。

但是我不知道错误实际上是什么。 ;-(

欢迎任何提示!问候雷内ps:我的脚本来源:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;

public class test : MonoBehaviour {

    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {

    }
    private static void Dump(object o)
    {
        string json = JsonConvert.SerializeObject(o, Formatting.Indented);
        Console.WriteLine(json);
    }
}
c# json unity3d namespaces json.net
2个回答
0
投票

我发现合并Newtonsoft.Json的最简单方法是转到NuGet site,并手动下载该软件包。然后,将所有文件解压缩到资产目录下的“插件”文件夹中,即Assets / Plugins / Json.NET。

您还应该将播放器脚本运行时版本设置为.NET4.x。我还将API兼容性设置为.NET Standard 2.0。尽管虽然推荐,但不是必需的。


0
投票

建议使用已准备的Newtonsoft.Json分支之一,该分支已对其进行了更改以与Unity3D兼容。它们比NuGet软件包更易于使用,并且与构建到AOT目标(例如Android,iOS,WebGL等)时会在运行时失败的官方NuGet软件包不同,它们都支持此功能。这是前三名:

jilleJr的变体是撰写本文时唯一的活动fork。其他人已停止开发。

安装说明取自jilleJr's wiki

打开/Packages/manifest.json,添加jillejr的作用域,然后将其添加到依赖项列表中。

Àla:

{
  "scopedRegistries": [
    {
      "name": "Packages from jillejr",
      "url": "https://npm.cloudsmith.io/jillejr/newtonsoft-json-for-unity/",
      "scopes": ["jillejr"]
    }
  ],
  "dependencies": {
    "jillejr.newtonsoft.json-for-unity": "12.0.201",

    // ...
  }
}

// ...表示manifest.json中包含的其余软件包,例如所有"com.unity.*"依赖项

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.