我正在尝试使用 Xamarin.Forms 在 Visual Studio for mac 中创建一个应用程序。在此应用中,我使用 Xamarin.Auth 来存储一些用户详细信息。现在我想使用 JSON 添加与 API 的连接。我添加了 System.Json 并添加了我的代码。但问题是我得到了错误:
Error CS0433: The type 'JsonValue' exists in both 'System.Json, Version=2.0.5.0' and 'Xamarin.Auth' (CS0433).
我在项目中删除并添加了 Xamarin.Auth。我在 visual studio 关闭时删除了 OBJ 和 BIN 文件夹,启动 VS,清理解决方案,重建解决方案并再次尝试,但仍然出现相同的错误。我似乎无法找出问题所在。
我不太确定它是否有帮助,但这是发生错误的代码片段,我知道该函数目前不返回任何内容,但我只是想弄清楚如何做 JSON/API 调用并获取代码以无错误地编译:
public class DBhandler
{
public async Task<List<Object>> GetItemsFromApiASync(Type callingClass, string apiDir, string apiFile)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(ApiAddress + apiDir + apiFile));
request.ContentType = "application/json";
request.Method = "Get";
using (WebResponse response = await request.GetResponseAsync())
{
using (Stream stream = response.GetResponseStream())
{
System.Json.JsonValue jsonDoc = await Task.Run(() => System.Json.JsonObject.Load(stream));
object[] parametersArray = new object[] { jsonDoc };
MethodInfo methodInfo = callingClass.GetMethod("ConvertApiResultToObject");
methodInfo.Invoke(methodInfo, parametersArray);
}
}
return null;
}
最佳答案
我在创建引用 Xamarin.Auth 和其他一些 NuGet 包以及 Facebook Xamarin 组件的 Xamarin Android 项目时遇到了同样的问题。我能够简单地从我的项目引用中删除 System.Json,然后我的项目就能够编译和运行。
关于c# - 错误 CS0433 : The type 'JsonValue' exists in both 'System.Json, Version=2.0.5.0' and 'Xamarin.Auth' (CS0433),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47147425/