JSON <=> Java 与 J2objc 转换良好的对象映射器

JSON <=> Java Object Mapper which translates well with J2objc

我使用 org.json.* 类,它们是 j2objc 发行版的一部分。到目前为止,我的 DTO 类 和 JSON 对象的映射是手工制作的。 我知道有 GSOn 和 Jackson。

是否有一个 JSON 到 Object Mapper 库,它可以很好地与 J2objc 一起翻译,并且在翻译后的 Objective-C 代码中也能很好地工作?

要将 json 数据转换为 java 对象,您可以使用:

  1. Jackson
  2. Gson

关注 this link or this link 获得不错的 GSON 教程。

我个人用的是GSON,是jsonjava object转换的最佳库

我不知道 j2objc 的转换部分,但如果你想用 iOS 代码

做类似的事情,你可以按照 this answer

编辑

根据this answer, j2objc requires source code for conversion. You will get full source code from here

现在,重要的部分 Gson 可以转换为 j2objc,您可以找到测试存储库来测试对 gson-2.3j2objc [=28= 的支持].

Jackson 和 GSON 是两个最好的库,并且都使用 j2objc 为来自不同团队的 iOS 应用程序进行了翻译(尽管我知道没有 public 端口)。

不过,如果您控制应用程序的服务器端,protocol buffers are generally faster than any JSON->Java alternative. That is why they're used by most of Google's iOS apps, including Inbox and Sheets that use j2objc. j2objc now publicly supports protocol buffers