Unity Newtonsoftプラグインはiosでjsonの問題と逆シーケンス化の問題をシーケンス化できません

5639 ワード

Newtonsoftは最も使用量の多いjsonプラグインで、私はunityでこのプラグインを引用して、ios端でオブジェクトをjsonにシーケンス化する時問題が発生して、私達は最初にネット上の学習資料あるいはその他の地方でjson解析クラスを定義することを見つけた時、各変数はすべて{get;set;}を追加しますフィールドは属性ブロックになりますが、iosシーケンス化するとシーケンス化に失敗し、自分で長い間探しても問題が見つからないので、ここで記録します.
参照リンクUnity iOS(De)SerializeObject()doesnt work
リンクの中の方法はシーケンス化だけでなく逆シーケンス化にも役立つようですが、unityプログラムはiosでNewtonsoftを使って逆シーケンス化できない問題は別の方法で解決しました.この方法は少し煩雑で,本論文の方法を試してみることができる.Unity NewtonSoftプラグイン逆シーケンス化jsonエラーUnable to find a constructorおよび逆シーケンス化されたオブジェクトに値がない問題
これは変更前のコードです.
public class SearchConditionInfo 
{
    public string areaTag { get; set; }
    public int exhibitionId { get; set; }
    public string hallTag { get; set; }

    [Preserve]
    public SearchConditionInfo(string areaTag, int exhibitionId, string hallTag)
    {
        this.areaTag = areaTag;
        this.exhibitionId = exhibitionId;
        this.hallTag = hallTag;
    }

    [Preserve]
    public SearchConditionInfo()
    {

    }

}

これは変更後のコードです
public class SearchConditionInfo 
{
    public string areaTag;
    public int exhibitionId;
    public string hallTag;

    [Preserve]
    public SearchConditionInfo(string areaTag, int exhibitionId, string hallTag)
    {
        this.areaTag = areaTag;
        this.exhibitionId = exhibitionId;
        this.hallTag = hallTag;
    }

    [Preserve]
    public SearchConditionInfo()
    {

    }

}