将NSDictionary转成json格式

//转json 
+(void)jsonTostring:(NSDictionary *)dict
{
    BOOL isYes = [NSJSONSerialization isValidJSONObject:dict];
    if (isYes)
    {
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:0 error:NULL];
        [jsonData writeToFile:@"/Users/SunnyBoy/Sites/JSON_XML/dict.json" atomically:YES];
        NSLog(@"==============================\n\n\n%@\n\n\n==============================",
              [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]);
    }
    else
    {
        NSLog(@"JSON数据生成失败,请检查数据格式");
    }
}

你可能感兴趣的:(将NSDictionary转成json格式)