C# Unity3d SimpleJSON向JSONClass添加int
我正在使用Unity3d。我想将C# Unity3d SimpleJSON向JSONClass添加int,c#,unity3d,simplejson,C#,Unity3d,Simplejson,我正在使用Unity3d。我想将int添加到JSONClass 例如,我需要json:{“attr”:4} JSONClass cl = new JSONClass(); 我试过这个: cl["attr"].AsInt = 4; 这是: cl["attr"] = new JSONData(4); 以及任何其他情况。无论如何,我得到了{“attr”:“4”}其中4是字符串 如何将int添加到它?在当前的实现中,这是不可能的 因此,我添加了新类型: public enum JSONBinary
int
添加到JSONClass
例如,我需要json:{“attr”:4}
JSONClass cl = new JSONClass();
我试过这个:
cl["attr"].AsInt = 4;
这是:
cl["attr"] = new JSONData(4);
以及任何其他情况。无论如何,我得到了{“attr”:“4”}
其中4
是字符串
如何将
int
添加到它?在当前的实现中,这是不可能的
因此,我添加了新类型:
public enum JSONBinaryTag
{
Array = 1,
Class = 2,
Value = 3,
IntValue = 4,
DoubleValue = 5,
BoolValue = 6,
FloatValue = 7,
LongValue = 8,
String = 9, // <-- new
Number = 10 // <-- new
}
并更改了toString()
方法:
public override string ToString(){
if (m_Type == JSONBinaryTag.String)
return "\"" + Escape(m_Data) + "\"";
else
return Escape(m_Data);
}
现在,
int
,float
,double
将被添加为不带“
”的数字。看起来是这样的:{“attr”:4}
你怎么看
JSONClass cl = new JSONClass();
要使用just do:
JsonHelper.Json(myObject);
您可以将其用于对象、游戏对象、可编写脚本的对象、单一行为等。我认为由于反射的原因,它的速度较慢。