Object serialization - from C# or java to Objective C

↘锁芯ラ 提交于 2019-12-23 12:56:09

问题


Server side - C# or java

Client side Objective C

I need a way to serialize an object in C#\java and de-serialize it in Objective C. I'm new to Objective C and I was wondering where I can get information about this issue.

Thanks.


回答1:


Apart from the obvious JSON/XML solutions, protobuf may also be interesting. There are Java//c++/python backends for it and 3rd parties have created backends for C# and objective-c (never used that one though) as well.

The main advantages are it being much, much faster to parse[1], much smaller[2] since it's a binary format and the fact that versioning was an important factor from the beginning.

[1] google claims 20-100times compared to XML

[2] 3-10times according to the same source

Another technology similar to protobufs is Apache Thrift.

Apache Thrift is a software framework for scalable cross-language services development. Apache Thrift allows you to define data types and service interfaces in a simple definition file. Taking that file as input, the compiler generates code to be used to easily build RPC clients and servers that communicate seamlessly across programming languages.




回答2:


JSON for relatively straight forward object graphs XML/REST for more complex object graphs (distinction between Arrays / Collections / nested arrays etc)




回答3:


Sudzc. I am using it. It is pretty easy to invoke a Webservice from i-os app.

You dont have to write code to serialize object.




回答4:


JSON is probably the best choice, because:

  • It is simple to use
  • It is human-readable
  • It is data-based rather than being tied to any more complex object model
  • You will be able to find decent libraries for import/export in most languages.

Serialisation of more complex objects is IMHO not a good idea from the perspective of portability since often one language/platform has no effective way of expressing a concept from another language / platform. e.g. as soon as you start declaring "types" or "classes" of serialised objects you run into the thorny issue of differing object models between languages.




回答5:


On iOS there are couple of JSON frameworks and libraries with an Objective-C API:

  • JSONKit
  • SBJson
  • TouchJson

are probably the most prominent.

JSONKit is fast and simple, but can only parse a contiguous portion of JSON text. This means, you need to save downloaded data into a temporary file, or you need to save all downloaded JSON text into a NSMutableData object (kept in memory). Only after the JSON text has been downloaded completely you can start parsing.

SBJson is more flexible to use. It provides an additional "SAX style" interface, can parse partial input and can parse more than one JSON document per "input" (for example several JSON documents per network connection). This is very handy when you want to connect to a "streaming API" (e.g. Twitter Streaming API), where many JSON documents can arrive per connection. The drawback is, it is a much slower than JSONKit.

TouchJson is even somewhat slower than SBJson.

My personal preference is some other, though. It is faster than JSONKit (20% faster on arm), has an additional SAX style API, can handle "streaming APIs", can simultaneously download and parse, can handle very large JSON strings without severely impacting memory foot-print, while it is especially easy to use with NSURLConnection. (Well, I'm probably biased since I'm the author).

You can take a look at JPJson (Apache License v2):

JPJson - it's still in beta, though.



来源:https://stackoverflow.com/questions/10423016/object-serialization-from-c-sharp-or-java-to-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!