我在NSData中得到类似的内容,我想将其打印为NSString数据,所以我可以为此获得一些解决方案。
我的数据是
(< 30820605 308204ed a0030201 02021011 b5aff6d9 6c725e0d 33105e6c 6115a930 0d06092a 864886f7 0d01010b 05003044 310b3009 06035504 06130255 53311630 14060355 040a130d 47656f54 72757374 20496e63 2e311d30 1b060355 04031314 47656f54 72757374 2053534c 20434120 2d204733 301e170d 31363032 30333030 30303030 5a170d31 37303230 32323335 3935395a 30818431 0b300906 03550406 1302494e 3110300e 06035504 08130748 61727961 6e613110 300e0603 55040714 07477572 67616f6e 31243022 06035504 0a141b50 726f7469 6e757320 496e666f 74656368 20507674 2e204c74 642e3115 30130603 55040b14 0c50726f 64756374 20546561 6d311430 12060355 0403140b 2a2e7472 75706179 2e696e30 82012230 0d06092a 864886f7 0d010101 05000382 010f0030 82010a02 82010100 b561a9fa 80f7e7f7 c9e64b02 05259a84 c73682d6 b3feee24 cbf04511 18667669 52f62331 a1056106 595b22fb db63cc4b c700e90f 0a1d24cb ea8f253c 3d7c8a57 5abd8f86 62c4e866 bbd0ace9 2c2eef5a 30046e48 a83d374b ef8f8170 cfa703d3 0099ff45 559031f8 53e8a67d af6552c2 4ff628c3 9979e3e0 62a5cc9a d73cb5fa a3ef6a45)
我想要的字符串格式相同的数据。
我正在使用这段代码
NSString *myString = [NSString stringWithUTF8String:[remoteCertificateData bytes]];
但我对myString
的评分为零。
答案 0 :(得分:0)
你可以使用,
you shouldn't use opam as root
如果数据以空值终止,则应改为使用
NSString* newStr = [[NSString alloc] initWithData:theData
encoding:NSUTF8StringEncoding];
如果NSData不是UTF-8编码的,那么你将获得nil。
有关进一步参考,请参阅以下链接:
请看看这个。
答案 1 :(得分:0)
您不需要匹配string
。只需转换NSData
中的字符串,如:
NSData* data = [str dataUsingEncoding:NSUTF8StringEncoding];
然后比较NSData。
答案 2 :(得分:0)
您可以使用以下代码片段将NSData转换为NSString:
// try to see if the locale has been set as a _locale routing parameter
if ($locale = $request->attributes->get('_locale')) {
$request->getSession()->set('_locale', $locale);
$request->setLocale($locale); // seems that it's SIGNIFICANT
} else {
// if no explicit locale has been set on this request, use one from the session
$request->setLocale($request->getSession()->get('_locale', $this->defaultLocale));
}