我希望在联合中反序列化这一点,并取得了一些成功,但似乎被困在了双数组上。以下是一些JSON (仅显示了相关内容)
{“城市”:[{“名称”:“伦敦”、“纪念碑”:{“等级”:15、"objBeingIntroduced":“无”}、{“层次”:25、"objBeingIntroduced":"df“}}、”谜题“:[{ "puzzleId":1,“移动”:[{ "x":3,"y":3,"xInc":1,"yInc":0 },{ "x":5,"y":3,"xInc":-1,"yInc":0 },{ "x":4,"y":3,"xInc":0,"yInc":1},{ "x":4,"y":5,"xInc":0,"yInc":-1 },“正方形”:{ "x":3,"y":3,"type":"d“},{ "x":5,"y":3,"type":"d”},{ "x":4,"y":5,“类型”:"d“}] }
您将如何在Unity中进行反序列化?
我可以抓取所有细节的拼图部分,除了移动类别,因为这是一个双数组。这是我到目前为止所拥有的
[System.Serializable]
public class LevelStructure
{
public int puzzleId;
public List<Moves> moves = new List<Moves>();
public Squares[] squares;
}
[System.Serializable]
public class Levels
{
public LevelStructure[] result;
}
[System.Serializable]
public class Squares
{
public int x;
public int y;
public string type;
}
[System.Serializable]
public class Moves
{
public Move[] moves;
}
[System.Serializable]
public class Move
{
public int x;
public int y;
public int xInc;
public int yInc;
}我似乎想不出如何做像“纪念碑”和“移动”这样的双数组。如能提供任何建议,我们将不胜感激。
既然我相信这个结构很好,那么如何将json实际加载到这些类中呢?
谢谢
发布于 2019-11-09 07:31:38
尽管您应该认真考虑一下您的结构并创建您自己的代码,以下是json2csharp.com可以为您的代码所做的工作:
public class Monument
{
public int levels { get; set; }
public string objBeingIntroduced { get; set; }
}
public class City
{
public string name { get; set; }
public List<Monument> monuments { get; set; }
}
public class Square
{
public int x { get; set; }
public int y { get; set; }
public string type { get; set; }
}
public class Puzzle
{
public int puzzleId { get; set; }
public List<List<>> moves { get; set; }
public List<Square> squares { get; set; }
}
public class RootObject
{
public List<City> cities { get; set; }
public List<Puzzle> puzzles { get; set; }
}https://stackoverflow.com/questions/58777279
复制相似问题