base64로 저장된 문자열을로드하고 싶지만 항상이 오류가 발생합니다. SimpleJson 클래스 (http://wiki.unity3d.com/index.php/SimpleJSON)를 사용하고 있습니다.JSON (문자열/base64)을 비 직렬화하는 중 오류가 발생 했습니까?
예외 : JSON을 비 직렬화하는 동안 오류가 발생했습니다. 미지의 태그 66 SimpleJSON.JSONNode.Deserialize (System.IO.BinaryReader aReader) (자산/플러그인/SimpleJSON.cs에서 512)
내 코드 : 여기
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();
이 방법은 클래스에서 :
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);
}
}
}
감사
base64로 압축을 해제하십시오 문자열을 구문 분석하기 전에 문자열. – rdodev
@rdodev 감사합니다. 어떻게 할 수 있습니까? 나는'var base64 = System.Convert.FromBase64String (str); '을 시도하지만 그것을하는 방법이 아닌 것 같다. – Paul
아래 내 대답은 도움이 될 것입니다. – rdodev