I just want to serialize some data and deserialize it back, and it must work on iOS platform. Json.NET does not works on iOS. The JsonFX can serialize data and string looks like string serialized by Json.Net, but JsonFX can't deserialize data back. Here is simple code which gives me next error
InvalidCastException: Cannot cast from source type to destination type.
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
using Pathfinding.Serialization.JsonFx;
public class jsonTest : MonoBehaviour {
public Text text;
public List<ChapterModel> chapters;
// Use this for initialization
void Start () {
chapters = new List<ChapterModel>();
for(int i=0; i<2; i++)
{
var cm = new ChapterModel();
cm.pages = new List<PageModel>();
cm.id = i;
for(int j =0; j<2; j++)
{
var pm = new PageModel();
pm.BackgroundArt = j.ToString();
cm.pages.Add(pm);
}
chapters.Add(cm);
}
Debug.Log(JsonReader.Deserialize<List<ChapterModel>>(JsonWriter.Serialize(chapters)).Count);
}
}
Is anyone knows how to fix it?
After playing around a little bit with JsonFX I found out that it's quite tricky to use:
However, if we let our JSON know a
typehint
, it should be fine. What's funny, it's not:You might want to play a little more with it or stick with ugly version I provided above.