使用JSON读取iOS中的游戏关卡数据

我想使用JSON来存储关于我的游戏的数据,并将其读入到我的Objective-C代码中。

所以我的TwinstonesBoardModel.m文件有以下几种方法(这是在游戏开始时为了设置板上对象的位置而被调用的第一种方法)。 我不知道为什么,但为了清晰起见,我将对象初始化划分为多个方法。

// sets the board positions for the stones - (void)setToInitialStateMain { // clear board so each level-load is free of previous data [super clearBoard]; // set the state of two stone objects and their positions [super setCellState:BoardCellStateStoneOne forColumn:0 andRow:0]; [super setCellState:BoardCellStateStoneTwo forColumn:2 andRow:3]; } - (void)setToInitialStateHorizontal { [super clearBoard]; [super setHBarCellState:HorizontalState forHBarCol:0 andHBarRow:1]; } 

而且我还有3个额外的方法用于类似上面的使用,只是设置位置。 我想要做的是在JSON文件中提供100个级别的位置和状态,以便根据级别select进行读取。 所以如果我select54级,上面的函数被调用,JSON文件54级的位置和状态被应用。

我的状态是:

  typedef NS_ENUM(NSUInteger, BoardCellState) { BoardCellStateEmpty = 0, BoardCellStateStoneOne = 1, BoardCellStateStoneTwo = 2, BoardCellStateTarget = 3, HorizontalState = 4, HorizontalStateEmpty = 5, GhostHorizontalState = 6, VerticalState = 7, VerticalStateEmpty = 8, GhostVerticalState = 9, IntersectorState = 10 }; 

而我正在处理位置值0-4。

我怎么去做这个? 我是从外部文件阅读水平的新手。 我可以绕开硬编码的所有位置,但是这将花费大量的时间,而且肯定是非常低效的。