ios几种数据格式转换
1. NSString转换成NSData
NSString* str = @"teststring"; NSData* data = [str dataUsingEncoding:NSUTF8StringEncoding];
2. NSData转换成NSString
NSString *aString = [[NSString alloc] initWithData:adataencoding:NSUTF8StringEncoding];
3. JSON格式的NSString转换成NSMutableDictionary
NSError *err = nil; NSArray *arr = [NSJSONSerialization JSONObjectWithData:[str dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:&err]; // access the dictionaries NSMutableDictionary *dict = arr[0]; for (NSMutableDictionary *dictionary in arr) { // do something using dictionary }
4. NSMutableDictionary转换成NSString
未完待续...