- Home /
JSON vs XML for Unity C#
which Serialization method is best for Unity XML or JSON? I'm currently writing my scripts in C#.
Locally or to a server? You are best off with binary formatting for speed and size - use a text based format when sending data to a server or if you really want it to be human readable and editable.
Answer by idunlop_oefun · Aug 03, 2012 at 11:28 PM
For pulling data from a server JSON is better because it's less bandwidth than XML - especially for mobile devices.
For storing user preferences, like a bool or int etc. use PlayerPrefs (see the documentation).
For storing things on disk it really depends on what your trying to accomplish. You can create your own format for binary files or read / write json data if needed.
If the amount of data I was trying to serialize was huge (i.e. a significant % of the devices capability) I'd probably want to use as compact a format as possible - which implies some sort of raw packed data format.
I'd just point out that binary formatter can serialize most classes to a compressed format that you don't have to make up yourself.
Yes, generally the only good reason to use a humanreadable format is to make it humanreadable ;) For savegames it's usually unwanted to make it humanreadable, so a binary format is the best bet in such a case.
But as stated several times here, it depends on the situation. This is lika you ask what's the best car or what's the best hammer. There are very different models out there, it just depends on the usage.
Ok I will try to use a binary format Because I don't want it to be readable and editable. Are there any good tutorials on how to setup a binary format?