Command-line tool for converting PLIST to JSON?

后端 未结 7 1619
粉色の甜心
粉色の甜心 2020-12-12 10:47

Is there a command line tool available for converting .plist files to JSON?

If not, what would be the approach for creating one using Objective-C or C on a Mac? For

7条回答
  •  天涯浪人
    2020-12-12 10:53

    There is a native way, to convert plist's to json. It's called NSJSONSerialization.

    Here is an example on how to use it, and convert a plist file to a json file:

    NSDictionary *plistDict = [NSDictionary dictionaryWithContentsOfFile:@"input.plist"];
    
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:plistDict options:NSJSONWritingPrettyPrinted error:&error];
    NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    [jsonString writeToFile:@"output.json" atomically:NO encoding:NSUTF8StringEncoding error:&error];
    

提交回复
热议问题