在c#unity3d中使用newtonsoft json进行激活

时间:2017-09-09 08:01:45

标签: c# json unity3d serialization json.net

我在下面有一个类,我试图用NewtonsoftJson

序列化它

示例:

abcW = new ABCListWrapper();
abcW = getabcWDataObject();
string abcData = JsonUtility.ToJson(abcW);

如果我使用上面的行来序列化对象,我将获得GameObject b,c序列化的json字符串中的数据为"gameObject":{"instanceID":844016}"

abcW = new ABCListWrapper();
abcW = getabcWDataObject();
string abcData = JsonConvert.SerializeObject(abcW);

如果我使用上面的行来序列化对象我没有获得序列化json字符串中的 GameObject b, c数据。

[序列化]

public class ABC : ISerializable
{
    //SerializableDictionary source: http://www.jankowskimichal.pl/en/2010/10/serializabledictionary/

    public SerializableDictionary<int, ExampleClass> a = new SerializableDictionary<int, ExampleClass>();

    public GameObject b;

    public GameObject c;

    public bool d = false;

    public ABC e;

    public int f;

    public string g = "";

    public int h = -1;

    public int i = -1;

    public int j = -1;

    public string k = "default";

    public XYZ l = XYZ.P;
}

[Serializable]
public enum XYZ
{
    P,
    Q
}


[Serializable()]
public class ABCListWrapper : ISerializable
{

    public List<ABC> abcMappings = new List<ABC>();
    public string version = "1.53";
    public float interval;
}

我如何使用JsonConvert.SerializeObject(abcW)并使给定对象中的GameObject b,c数据包含在序列化对象中,而我在使用JsonUtility.ToJson()时得到了这些数据。我有一个复杂的对象,我需要使用Newtonsoft来序列化和反序列化。

感谢。

0 个答案:

没有答案