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:
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using EasyJSON;
public class EasyJSONExample : MonoBehaviour {
IEnumerator Start () {
// Let's construct our entity
Box box = new Box();
box.dimension = new Vector3(2f, 1.5f, 3f);
Product product1 = new Product();
product1.name = "Cheese";
product1.description = "Cheese made by a firefighter from Boston, Texas.";
product1.price = 9.99f;
box.products.Add(product1);
Product product2 = new Product();
product2.name = "Ham";
product2.description = "Ham from Tokyo, Argentina.";
product2.price = 69.69f;
box.products.Add(product2);
Product product3 = new Product();
product3.name = "Bread";
product3.description = "Bread gently cooked by your mother.";
product3.price = 13.31f;
box.products.Add(product3);
// Serialize the entity into a JSON string
string output = Serializer.Serialize<Box>(box);
Debug.Log("Compressed Json:\n" + output);
string prettyOutput = Serializer.Serialize<Box>(box, true);
Debug.Log("Pretty Json:\n" + prettyOutput);
// Now we deserialize the JSON string to construct the entity
Box deserializedBox = Serializer.Deserialize<Box>(output);
// or Box deserializedBox = output.Deserialize<Box>();
Debug.Log(string.Format("Box with {0} product(s) and dimension {1}.", deserializedBox.quantity, deserializedBox.dimension));
// We can also deserialize a JSON string directly from a WWW object
WWW www = new WWW("http://www.takohi.com/data/unity/assets/easyjson/box.json");
yield return www;
Box wwwBox = www.Deserialize<Box>();
Debug.Log(string.Format("Box with {0} product(s) and dimension {1}.", wwwBox.quantity, wwwBox.dimension));
}
public class Product {
public string name;
public string description;
public float price;
}
public class Box {
public Vector3 dimension;
public List<Product> products = new List<Product>();
public int quantity {
get {
return products.Count;
}
}
}
}