我正在从他们的 iOS 通讯簿/Contacts.app 中的用户联系人中获取图像。并将它们放入字典中以 JSON 格式上传。
我收到以下错误:
2012-12-05 10:38:01.286 ContactsApp[6247:713f] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (__NSCFData)'
*** First throw call stack:
(0x2de6012 0x286ce7e 0x2de5deb 0x20926fe 0x2096b21 0x2dd3cdf 0x2dd387d 0x2dd37c5 0x20966fa 0x209262d 0x2096b21 0x2dd3cdf 0x2dd387d 0x2dd37c5 0x20966fa 0x209262d 0x20969af 0x2ddfe7c 0x2ddfa16 0x2ddf925 0x20968b8 0x2092679 0x2096b21 0x2dd3cdf 0x2dd387d 0x2dd37c5 0x20966fa 0x209262d 0x20923bd 0x209579c 0x1cad5 0x67475 0x66a87 0x14399cd 0x746008f 0x3dc253f 0x3dd4014 0x3dc52e8 0x3dc5450 0x90e36e12 0x90e1ecca)
libc++abi.dylib: terminate called throwing an exception
我使用了以下代码:
if (ABPersonHasImageData(addressBookContact)) {
NSMutableDictionary *imageDictionary = [NSMutableDictionary dictionary];
NSData *thumbnailImageData = (__bridge NSData *)ABPersonCopyImageDataWithFormat(addressBookContact, kABPersonImageFormatThumbnail);
NSData *originalImageData = (__bridge NSData *)ABPersonCopyImageDataWithFormat(addressBookContact, kABPersonImageFormatOriginalSize);
if (thumbnailImageData) [imageDictionary setObject:thumbnailImageData forKey:@"thumbnailImage"];
if (originalImageData) [imageDictionary setObject:originalImageData forKey:@"originalImage"];
[contactDictionary setObject:imageDictionary forKey:@"image"];
}
当我尝试将数组放入此请求时发生错误:
[addressBookArray addObject:contactDictionary];
if ([addressBookArray count] % 15 == 0) {
// I'm using AFNetworking
[[APIClient sharedClient] requestWithMethod:@"POST" path:@"cmd/addContact" parameters:@{ @"addressBookEntries" : addressBookArray }];
[addressBookArray removeAllObjects];
}