转自:http://mobile.51cto.com/hot-404914.htm
- NSString *dictString = [dict JSONFragment];//组合成的。
用这个就行了。。。
- dictString==={"content":"Sadgfdfg","phoneno":"","email":"1049055935@qq.com"}===
- // 十六进制转换为普通字符串的。
- + (NSString *)stringFromHexString:(NSString *)hexString { //
- char *myBuffer = (char *)malloc((int)[hexString length] / 2 + 1);
- bzero(myBuffer, [hexString length] / 2 + 1);
- for (int i = 0; i < [hexString length] - 1; i += 2) {
- unsigned int anInt;
- NSString * hexCharStr = [hexString substringWithRange:NSMakeRange(i, 2)];
- NSScanner * scanner = [[[NSScanner alloc] initWithString:hexCharStr] autorelease];
- [scanner scanHexInt:&anInt];
- myBuffer[i / 2] = (char)anInt;
- }
- NSString *unicodeString = [NSString stringWithCString:myBuffer encoding:4];
- NSLog(@"------字符串=======%@",unicodeString);
- return unicodeString;
- }
- //普通字符串转换为十六进制的。
- + (NSString *)hexStringFromString:(NSString *)string{
- NSData *myD = [string dataUsingEncoding:NSUTF8StringEncoding];
- Byte *bytes = (Byte *)[myD bytes];
- //下面是Byte 转换为16进制。
- NSString *hexStr=@"";
- for(int i=0;i<[myD length];i++)
- {
- NSString *newHexStr = [NSString stringWithFormat:@"%x",bytes[i]&0xff];///16进制数
- if([newHexStr length]==1)
- hexStr = [NSString stringWithFormat:@"%@0%@",hexStr,newHexStr];
- else
- hexStr = [NSString stringWithFormat:@"%@%@",hexStr,newHexStr];
- }
- return hexStr;
- }
再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow