首页 > 代码库 > NSString NSDictionary 和char *类型之间的转换

NSString NSDictionary 和char *类型之间的转换

1.字典-->字符串

  • NSData *jsonData = http://www.mamicode.com/[NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&parseError];
  • NSString *string = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];  

2.1NSString --> char *

  • char *charType = [string cStringUsingEncoding:NSASCIIStringEncoding];  

2.2.char * -->NSString

  • NSString *string_content = [[NSString alloc] initWithCString:(const char*)char   encoding:NSASCIIStringEncoding]; 
 

NSString NSDictionary 和char *类型之间的转换