之前寫過類似的方法 今天寫這個 的目的是 應對開發過程中面對 服務端數據剛定下模型 但是接口不通 的情況下 不耽誤客戶端開發進度
+ (id)getJsonDataJsonname:(NSString *)jsonname { NSString *path = [[NSBundle mainBundle] pathForResource:jsonname ofType:@"geojson"]; NSData *jsonData = [[NSData alloc] initWithContentsOfFile:path]; NSError *error; id jsonObj = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error]; if (!jsonData || error) { //DLog(@"JSON解碼失敗"); return nil; } else { return jsonObj; } }
不需要頭文件 這個類方法 就是 在工程中插入一個json 格式的文件 自己 編寫假數據
然后 利用這個方法 讀取json
愉快開發 就是這樣煉成的