温州网站推广排名,网络营销论文1500字,系统更新,二手网站建设论文答辩ios plist 国际化我很高兴地宣布我的第一个开源项目java-plist-serializer可以帮助您将Java#xff08;尤其是基于Spring的应用程序#xff09;与iOS应用程序集成在一起。 背景 我正在将Java webapp作为后端并且客户端是iOS设备的项目。 最近#xff0c;我收到了创建Web服务… ios plist 国际化 我很高兴地宣布我的第一个开源项目java-plist-serializer可以帮助您将Java尤其是基于Spring的应用程序与iOS应用程序集成在一起。 背景 我正在将Java webapp作为后端并且客户端是iOS设备的项目。 最近我收到了创建Web服务的任务该服务返回plist iOS中使用的Property List数据格式作为响应。 为什么选择plist而不选择JSON或经典XML 如果您必须针对iOS 5.0进行开发则没有本机类可反序列化JSON。 核心iOS库支持“属性列表”格式因此反序列化为NSDictionary非常快速高效。 很少有plist –与Java有关的库但是每个库都需要做大量的手工工作并将Java对象逐步重写为Apple NS *类的Java等效类。 我认为没有人喜欢这种任务。 那就是为什么我开发了一个库用于以类似于XStream XML序列化的方式将Java对象序列化为Plist。 java-plist-serializer java-plist-serializer是托管在Github上的开源项目有助于开发Java应用程序和iOS应用程序之间的通信。 不依赖于任何与XML相关的库 PlistIgnore PlistAlias和命名策略可定制的输出 线程安全–可以在项目中用作单例 可扩展–可以轻松添加其他对象的处理程序 PlistView提供的Spring Framework集成 用法 库的核心是PlistSerializerImpl 。 为了将对象序列化为plist您必须创建PlistSerializerImpl的实例并调用序列化方法之一。 例如 输入类别 public class Post {private String title;private Integer views 0;private ListComment comments new ArrayListComment();private Author author;public Post(Author author, String title, Integer views) {this.title title;this.views views;this.author author;}
}public class Comment {private String content;private String author;public Comment(String author, String content) {this.content content;this.author author;}
}public class Author {private String name;
} 创建这些类的对象并plistSerializer.toXmlPlist方法 Post post new Post(new Author(jason bourne), java-plist-serializer introduction, 9);
post.addComment(new Comment(maciejwalkowiak, first comment));
post.addComment(new Comment(john doe, second comment));PlistSerializerImpl plistSerializer new PlistSerializerImpl();
String xml plistSerializer.toXmlPlist(post); xml变量将包含 ?xml version1.0 encodingUTF-8?!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd
plist version1.0dictkeyauthor/keydictkeyname/keystringjason bourne/string/dictkeycomments/keyarraydictkeyauthor/keystringmaciejwalkowiak/stringkeycontent/keystringfirst comment/string/dictdictkeyauthor/keystringjohn doe/stringkeycontent/keystringsecond comment/string/dict/arraykeytitle/keystringjava-plist-serializer introduction/stringkeyviews/keyinteger9/integer/dict
/plist Spring框架集成 为了返回plist作为Spring MVC控制器的响应您可以使用扩展AbstractView的 PlistView 。 有几种方法可以配置Spring MVC。 最容易理解的PlistView用法示例 Controller
public class BlogController {RequestMapping(value /loadBlogPost, method RequestMethod.GET)public ModelAndView loadBlogPost() {Post post new Post(new Author(jason bourne), java-plist-serializer introduction, 9);post.addComment(new Comment(maciejwalkowiak, first comment));post.addComment(new Comment(john doe, second comment));ModelMap model new ModelMap();model.addAttribute(RESULT, notification);return new ModelAndView(new PlistView(), model);}
} 更详细的文档可以在项目的github页面上找到 结论 随意叉延伸。 如果您发现任何问题请在github上报告。 参考 Java与iOS的对话来自Java 伙伴JCG合作伙伴 Maciej Walkowiak在Apple上向Apple plist序列化Java对象 该博客来自Software Development Journey博客。 翻译自: https://www.javacodegeeks.com/2012/07/java-talking-to-ios-java-objects-to.htmlios plist 国际化