Created
November 15, 2016 04:05
-
-
Save SongJiaqiang/0907923e94998fd86bab3e0e58b2cd68 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (NSString *)jsonFromDictionary:(NSDictionary *)dict { | |
| NSDictionary *plistDict = nil; | |
| if (dict != nil) { | |
| plistDict = dict; | |
| }else { | |
| NSString *path = [[NSBundle mainBundle] pathForResource:@"items.plist" ofType:nil]; | |
| NSArray *array = [NSArray arrayWithContentsOfFile:path]; | |
| plistDict = [NSDictionary dictionaryWithObject:array forKey:@"list"]; | |
| } | |
| NSError *error; | |
| NSData *jsonData = [NSJSONSerialization dataWithJSONObject:plistDict options:NSJSONWritingPrettyPrinted error:&error]; | |
| NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; | |
| [jsonString writeToFile:@"result.json" atomically:NO encoding:NSUTF8StringEncoding error:&error]; | |
| NSLog(@"jsonString: %@", jsonString); | |
| return jsonString; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment