I would like to load a string that was saved as a base64, but I always get this error. I am using the SimpleJson class (http://wiki.unity3d.com/index.php/SimpleJSON) :
Exception: Error deserializing JSON. Unknown tag: 66 SimpleJSON.JSONNode.Deserialize (System.IO.BinaryReader aReader) (at Assets/plugins/SimpleJSON.cs:512)
My code :
var I = new JSONClass();
I["author"]["name"] = "testName";
I["author2"]["name2"] = "testName2";
string str = I.SaveToCompressedBase64();
//output : QlpoOTFBWSZTWdFZTaIAAAdNgH/gEAAA etc.
//#Error deserializing JSON
string res = JSONClass.LoadFromBase64( str );//.ToString();
Here are the methods from the class :
public static JSONNode LoadFromBase64(string aBase64)
{
var tmp = System.Convert.FromBase64String(aBase64);
var stream = new System.IO.MemoryStream(tmp);
stream.Position = 0;
return LoadFromStream(stream);
}
public static JSONNode LoadFromStream(System.IO.Stream aData)
{
using(var R = new System.IO.BinaryReader(aData))
{
return Deserialize(R);
}
}
public static JSONNode Deserialize(System.IO.BinaryReader aReader)
{
JSONBinaryTag type = (JSONBinaryTag)aReader.ReadByte();
switch(type)
{
case JSONBinaryTag.Array:
{
int count = aReader.ReadInt32();
JSONArray tmp = new JSONArray();
for(int i = 0; i < count; i++)
tmp.Add(Deserialize(aReader));
return tmp;
}
case JSONBinaryTag.Class:
{
int count = aReader.ReadInt32();
JSONClass tmp = new JSONClass();
for(int i = 0; i < count; i++)
{
string key = aReader.ReadString();
var val = Deserialize(aReader);
tmp.Add(key, val);
}
return tmp;
}
case JSONBinaryTag.Value:
{
return new JSONData(aReader.ReadString());
}
case JSONBinaryTag.IntValue:
{
return new JSONData(aReader.ReadInt32());
}
case JSONBinaryTag.DoubleValue:
{
return new JSONData(aReader.ReadDouble());
}
case JSONBinaryTag.BoolValue:
{
return new JSONData(aReader.ReadBoolean());
}
case JSONBinaryTag.FloatValue:
{
return new JSONData(aReader.ReadSingle());
}
default:
{
throw new Exception("Error deserializing JSON. Unknown tag: " + type);
}
}
}
Thanks
var base64 = System.Convert.FromBase64String(str);but it does not seem to be the way to do it.