【问题标题】:Which namespace should I use to access Json operations? (Xamarin.Forms 2021 Year)我应该使用哪个命名空间来访问 Json 操作? (Xamarin.Forms 2021 年)
【发布时间】:2022-01-26 07:02:39
【问题描述】:

我尝试使用“使用 Newtonsoft.Json.Linq;” – GET ERROR – 不需要使用指令

dynamic stuff = JObject.Parse("{ 'Name': 'Jon Smith', 'Address': { 'City': 'New York', 'State': 'NY' }, 'Age': 42 }");

string name = stuff.Name;
string address = stuff.Address.City;

我也尝试使用“使用 Json.NET” – GET ERROR – Using 指令是不必要的

dynamic stuff = JsonConvert.DeserializeObject("{ 'Name': 'Jon Smith', 'Address': { 'City': 'New York', 'State': 'NY' }, 'Age': 42 }");

string name = stuff.Name;
string address = stuff.Address.City;

它只对我有用——“使用 Org.Json”——但我不明白如何使用这个库

为什么我会收到“不需要使用指令”的错误消息?

我使用 VS2019(8.10.16.2) Net.Standard.Library(2.0.3)

【问题讨论】:

    标签: c# xamarin.forms


    【解决方案1】:

    我尝试使用“使用 Newtonsoft.Json.Linq;” – GET ERROR – 不需要使用指令

    我能够重现此问题。 “不需要使用指令”意味着当前 C# 代码文件中的任何内容都没有引用 using 指令的命名空间中的非命名空间限定类型。当我们只添加using Newtonsoft.Json.Linq; 而不安装它时也会出现这种情况。

    在 Xamarin.Forms 中,从 NuGet 安装 Newtonsoft.Json 包将修复此错误。

    【讨论】:

      猜你喜欢
      • 2019-07-20
      • 1970-01-01
      • 2011-05-11
      • 2018-03-24
      • 1970-01-01
      • 2017-08-12
      • 1970-01-01
      • 2021-09-23
      • 1970-01-01
      相关资源
      最近更新 更多