c# - Xamarin iOS 项目中的 Newtonsoft.Json 反序列化对象

标签 c# xamarin.forms xamarin.ios json.net xamarin-live-player

我的 Xamarin.Forms 项目中出现一些非常奇怪的行为。

我正在从 REST API 检索一些序列化数据。然后我尝试使用 Json.NET 将其反序列化为一个对象。

这在 Android 上工作得很好,如果我将代码复制到 .NET 控制台应用程序,它也可以工作。但是在我的 iOS 项目中,对 .DeserializeObject() 的调用只返回 null。它不会以任何方式抛出错误或提示。

我确实找到了这个讨论:https://forums.xamarin.com/discussion/15152/deserialization-not-working-with-json-net-on-ios-device-ios-simulator-works ,但我没有首先链接所有程序集并尝试设置 T.J.Purtell.1752 建议的属性 也没有帮助。

谁能告诉我在这里做什么?

非常感谢!

一月

编辑

这是我尝试反序列化的示例响应:

[
   {
      "Isbn":{
         "Isbn10":"0099910101",
         "Isbn13":"9780099910107"
      },
      "Title":"A Farewell to Arms",
      "Authors":[
         "Ernest Hemingway"
      ],
      "Publisher":"Random House",
      "ReleaseDate":"1994",
      "PageCount":293,
      "Description":"In 1918 Ernest Hemingway went to war, to the 'war to end all wars'. He volunteered for ambulance service in Italy, was wounded and twice decorated. Out of his experiences came A Farewell to Arms. Hemingway's description of war is unforgettable. He recreates the fear, the comradeship, the courage of his young American volunteer and the men and women he meets in Italy with total conviction. But A Farewell to Arms is not only a novel of war. In it Hemingway has also created a love story of immense drama and uncompromising passion.",
      "ThumbnailUrl":"http://books.google.com/books/content?id=m68LhBiNv8YC&printsec=frontcover&img=1&zoom=1&source=gbs_api"
   },
   {
      "Isbn":{
         "Isbn10":"9044538780",
         "Isbn13":"9789044538786"
      },
      "Title":"Het huis van de namen",
      "Authors":[
         "Colm Tóibín"
      ],
      "Publisher":"Singel Uitgeverijen",
      "ReleaseDate":"2017-08-24",
      "PageCount":0,
      "Description":"Klytaimnestra heeft veel moeten doorstaan. Haar man heeft haar kind, haar mooie oudste dochter, geofferd aan de goden, en zij heeft hem niet kunnen tegenhouden. Hoe kan ze dit ooit te boven komen? En hoe zullen haar andere twee kinderen reageren op deze ontwrichtende gebeurtenis? Eén ding neemt ze zich voor: haar man zal dit met de dood moeten bekopen.",
      "ThumbnailUrl":"http://books.google.com/books/content?id=yl8yDwAAQBAJ&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api"
   }
]

最佳答案

刚回到这个问题。如果有人想知道:原来我最近不得不使用的 Xamarin Live Player 在 Json.NET 方面存在一些问题。 ( https://developer.xamarin.com/guides/cross-platform/live/limitations/ )

我知道这一定很蠢……好吧,也许我可以节省一些时间!

关于c# - Xamarin iOS 项目中的 Newtonsoft.Json 反序列化对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47379055/

相关文章:

c# - 无法在移动设备上滚动使用 Xamarin.Forms 创建的 xaml 页面

xamarin - 绑定(bind) iOS 框架会导致临时文件损坏

C# 对象初始值设定项 - 包括构造函数调用括号?

c# - Unity 中 invoke 或 ienumerator 是更好的方法吗?

c# - 新手继承问题

c# - 无法访问派生类中的基属性 (C#)

xaml - 如何在 Xamarin 中删除从 ListView 中选择的项目

c# - SOLID、MasterPages 和 ASCX?

iPhone:Retina 显示屏将字体写入 UIImage

ios - UINavigationController 在单击后退按钮时向下滚动