Created
March 9, 2014 16:26
-
-
Save edom18/9450290 to your computer and use it in GitHub Desktop.
NSDataの中身を確認する方法 ref: http://qiita.com/edo_m18/items/b39fa31cd5c094fd05b6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSLog(@"%@", [[NSString alloc] initWithData:data | |
encoding:NSUTF8StringEncoding]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void MQDumpNSData(NSData *data) | |
{ | |
// データ配列のポインタを得る | |
const unsigned char *ptr = [data bytes]; | |
unsigned long length = [data length]; | |
// 取得したデータ分の文字列配列を確保 | |
unsigned char s[length]; | |
for (int i = 0; i < length; i++) { | |
// ptrポインタから文字列を取り出し、ポインタアドレスを先に進める | |
s[i] = *ptr++; | |
} | |
NSLog(@"%s", s); //=> 人間が分かる形で出力される | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment