Search Unity

EasyJSON

Discussion in 'Assets and Asset Store' started by Takohi, Oct 23, 2014.

  1. Takohi

    Takohi

    Joined:
    May 14, 2014
    Posts:
    58
    We are glad to present you EasyJSON, bringing the power of JSON serialization and deserialization to Unity 3.5+ (both Free and Pro).

    EasyJSON allows you, thanks to only two functions, to serialize and deserialize any object you want including some built-in classes of Unity (Vector3, Color...). Also some extension methods have been added in order to use the features of EasyJSON directly from a string or WWW object.

    This asset also allows you to generate compressed JSON string (no space, no line break) for saving bandwidth or pretty JSON string (with identations and line breaks) that can be easily readable by people.

    It was successfully tested on every platform supported by Unity, including Windows Phone application.

    We wanted to make EasyJSON as easy as possible in order to let people without any programming skills to use all the power of JSON for exchanging data between applications or servers. Indeed, no programming skill is required, EasyJSON is very handy.

    You can check how easy it is to use this asset by checking the documentation and all available functions here:
    http://www.takohi.com/data/unity/assets/easyjson/documentation/

    The price: 2$.
    The asset is available on the asset store here.

    If you have any suggestion or any question, please feel free to ask!

    Here is a code example showing how EasyJSON can be used:
    Code (CSharp):
    1. using UnityEngine;
    2. using System;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using EasyJSON;
    6.  
    7. public class EasyJSONExample : MonoBehaviour {
    8.  
    9.     IEnumerator Start () {
    10.  
    11.         // Let's construct our entity
    12.         Box box = new Box();
    13.         box.dimension = new Vector3(2f, 1.5f, 3f);
    14.  
    15.         Product product1 = new Product();
    16.         product1.name = "Cheese";
    17.         product1.description = "Cheese made by a firefighter from Boston, Texas.";
    18.         product1.price = 9.99f;
    19.         box.products.Add(product1);
    20.  
    21.         Product product2 = new Product();
    22.         product2.name = "Ham";
    23.         product2.description = "Ham from Tokyo, Argentina.";
    24.         product2.price = 69.69f;
    25.         box.products.Add(product2);
    26.  
    27.         Product product3 = new Product();
    28.         product3.name = "Bread";
    29.         product3.description = "Bread gently cooked by your mother.";
    30.         product3.price = 13.31f;
    31.         box.products.Add(product3);
    32.  
    33.         // Serialize the entity into a JSON string
    34.         string output = Serializer.Serialize<Box>(box);
    35.         Debug.Log("Compressed Json:\n" + output);
    36.  
    37.         string prettyOutput = Serializer.Serialize<Box>(box, true);
    38.         Debug.Log("Pretty Json:\n" + prettyOutput);
    39.  
    40.         // Now we deserialize the JSON string to construct the entity
    41.         Box deserializedBox = Serializer.Deserialize<Box>(output);
    42.         // or Box deserializedBox = output.Deserialize<Box>();
    43.  
    44.         Debug.Log(string.Format("Box with {0} product(s) and dimension {1}.", deserializedBox.quantity, deserializedBox.dimension));
    45.  
    46.         // We can also deserialize a JSON string directly from a WWW object
    47.         WWW www = new WWW("http://www.takohi.com/data/unity/assets/easyjson/box.json");
    48.         yield return www;
    49.         Box wwwBox = www.Deserialize<Box>();
    50.  
    51.         Debug.Log(string.Format("Box with {0} product(s) and dimension {1}.", wwwBox.quantity, wwwBox.dimension));
    52.     }
    53.  
    54.     public class Product {
    55.         public string name;
    56.         public string description;
    57.         public float price;
    58.     }
    59.  
    60.     public class Box {
    61.         public Vector3 dimension;
    62.         public List<Product> products = new List<Product>();
    63.         public int quantity {
    64.             get {
    65.                 return products.Count;
    66.             }
    67.         }
    68.     }
    69. }
    70.  
     
    Last edited: Nov 5, 2014
  2. Takohi

    Takohi

    Joined:
    May 14, 2014
    Posts:
    58
    Version 1.2 of EasyJSON is now released.

    Changelog:
    • Fix bug making corrupted JSON if application is running where the country is writing floating numbers with comma (,).
    • Method to build a pretty JSON string.
     
  3. Masaco

    Masaco

    Joined:
    Jan 29, 2013
    Posts:
    2
    SPECIAL CHARACTER ENCODING/DECODING PROBLEM
    EasyJSON is a great library for json serialization. ORM works very well!
    However I have a problem with strings containing special characters (unicode and umlaut). Can you suggest some example how to resolve this?

    EXAMPLE:
    Product product= new Product();
    product.name = "王 is nöt wörking";
    stringoutput = Serializer.Serialize<Product>(product);
    Debug.Log("Compressed Json:\n" + output);

    RESULT OF SERIALIZATION: {"name":"??? is n??t w??rking"
     
  4. Takohi

    Takohi

    Joined:
    May 14, 2014
    Posts:
    58
    Hello Masaco and thank you for your reply!
    Where did you print the result of your serialization? In the Unity console? Can you try to print it in a UTF-8 encoded file?
    I will try to reproduce your bug on my side and see if I can fix it but I will need to also help me. I will do as fast as I can but I will need few days. Still you can contact me by email!
     
  5. mog-mog-mog

    mog-mog-mog

    Joined:
    Feb 12, 2014
    Posts:
    266
    I get AOT error on IOS. Have you tested it on IOS?
     
  6. Takohi

    Takohi

    Joined:
    May 14, 2014
    Posts:
    58
    We have tested on iOS and it runs perfectly. Is it you who sent us an e-mail with the debug log?
    If yes, please try to follow our instructions and let us know. We will help you to fix that.
     
  7. Takohi

    Takohi

    Joined:
    May 14, 2014
    Posts:
    58
    We are now facing two issues:
    - EasyJSON can raise some AOT errors for iOS environment.
    - EasyJSON is not working with Visual Studio.

    We will fix as soon as possible these issues. In the meanwhile, for those who bought EasyJSON and are facing these issues, we will offer you one of our other assets. Please contact us.
     
  8. berzerk

    berzerk

    Joined:
    Dec 23, 2014
    Posts:
    18
    Takohi, I just purchased EasyJSON to implement serialization for saving / loading in a Windows Store app. It was very easy to use and in 10 minutes everything was good to go.

    There are a few issues with the plugin for Windows Store Apps, here is a report of the compatibility that may help your development of the fixes:

    http://scan.xamarin.com/Home/Report?scanId=1acc7fb6-d1df-4c7c-8068-2069d5413db9

    Keep up the good work.
     
  9. Takohi

    Takohi

    Joined:
    May 14, 2014
    Posts:
    58
    Hello berzerk. Thank you a lot, this tool is very helpful!
     
  10. Railon23

    Railon23

    Joined:
    Jan 30, 2014
    Posts:
    32
    Hi Takohi,

    I love your plugin. Working great on Windows for developing and on Android. But now I want to build the iOS version and got an AOT error. Just saw this thread and your answer.
    Is there a workaround or an update available yet?

    Since I would like to use Umlaute in my project later, I'm also interested in the answer to the other question above.
    Do Umlaute work already or is there an update planned?

    Thanks
     
  11. Takohi

    Takohi

    Joined:
    May 14, 2014
    Posts:
    58
    I am sorry for all the inconveniences. Unfortunately, today, as far as I know, there is no workaround.
    For the encoding issue, I will try to do an update as soon as possible. For the AOT issue, I will do my best.

    Sorry again.
     
  12. Stals

    Stals

    Joined:
    Dec 1, 2014
    Posts:
    8
    Hi Takohi,
    The asset is looking great, but are you still planing to fix the AOT issue for iOS?
    Thanks
     
    Railon23 likes this.
  13. Magius96

    Magius96

    Joined:
    Feb 28, 2015
    Posts:
    12
    Just wanted to say that EasyJSON is the bomb! No seriously, I've looked at several different options for parsing and generating JSON files in Unity, and EasyJSON was the easiest to adopt, and it just flipping worked. Many of the other options I looked at don't even do object serialization. Like, you had to do the serialization of an object yourself by specifying each property to be serialized. (Take a look at SimpleJSON for an example....yucky).

    There's just one thing I'd like to see added to EasyJSON though. I'd like to be able to have a public property on a serialized object, that is flagged to not be serialized. Is that currently possible, or can that be added?
     
  14. Takohi

    Takohi

    Joined:
    May 14, 2014
    Posts:
    58
    Hello,

    Sorry for the late reply. Unfortunately, I don't have so much time right now so people will need to wait. But I would be happy if someone can help me to fix it.

    I'm very glad you like the assets. Unfortunately, this is currently not possible because to serialize an object, they need to be serializable, therefore flagged serializable. But I will add your recommendation to the todo list. Maybe for a future release. Thank you!
     
  15. Takohi

    Takohi

    Joined:
    May 14, 2014
    Posts:
    58
    Hello everybody and sorry for being late!

    I just published an update for EasyJSON that fix the issue for iOS and probably for some other platforms too! But first, it needs to be reviewed by the Asset Store team before being released.

    If you don't want to wait, feel free to contact me with the invoice number and I will send you the updated package!

    Again, truly sorry for the inconvenience.

    EDIT:
    It has been released and now available on Assets Store.
     
    Last edited: Dec 2, 2015
  16. kaaJ

    kaaJ

    Joined:
    Mar 21, 2007
    Posts:
    150
    Hi Takohi,

    The latest version of EasyJSON introduces serialization errors with animationcurves. In my case at least, public animations curves are not rebuilt. This was working without any issues in the previous version.
     
  17. Takohi

    Takohi

    Joined:
    May 14, 2014
    Posts:
    58
    Hello.
    No luck, the animation curves serialization was what was making the plugin not compatible with iOS devices... So I removed this support in order to target more platforms.
     
  18. kaaJ

    kaaJ

    Joined:
    Mar 21, 2007
    Posts:
    150
    OK... damn, just what I was using for my iOS game... Back to manual coding then.
     
  19. Takohi

    Takohi

    Joined:
    May 14, 2014
    Posts:
    58
    Sorry for the trouble. But this doesn't require too much effort to make it work:
    • Create your custom class that includes all parameters you want to save from a animation curves instance.
    • For saving, copy the values from the animation curves instance in the members of your custom class.
    • Serialize your custom class.
    • Deserialize when you need.
    • Copy back the values in animation curves.
     
  20. kaaJ

    kaaJ

    Joined:
    Mar 21, 2007
    Posts:
    150
    Yeah, that's what I was thinking as well.

    Thanks for the reply.
     
  21. Yukichu

    Yukichu

    Joined:
    Apr 2, 2013
    Posts:
    420
    Well, I decided this would save me some time, and it did... and it works well...

    Things I felt could have been conveyed more clearly:
    1. This does not deserialize monobehaviors. It serialized them 'okay' but of course lots of monobehavior members aren't saved, but that's okay. I realized I had to write conversion classes, which is cool I suppose. Works well.
    2. It does not serialize the parent class if this is a child class. This part I would assume work. I understand the monobehavior issue.

    Anyhow, all-in-all for 2 bucks it saved me an hour of my life, so worth it. Thanks,
     
  22. Aizee421

    Aizee421

    Joined:
    Nov 16, 2011
    Posts:
    5
    I've run into an issue with emoji codes not being parsed correctly. Unity spits out this error as an example:

    Exception: Error while parsing: invalid escape sequence '\u{1F3'
    ; context = <my life✌\u{1F3FD}️>
    EasyJSON.Serializer.Deserialize[Users] (System.String json)

    (the emoji icons don't show up in the unity console)

    Is EasyJson able to parse emoji's? Or is it just the brackets that aren't formatted correctly?

    Thanks.