0

I'm trying to convert Vcard/vcf information in the form of JSON to an NSData object. When I try to attach the NSData object, it's not displaying properly. Am I missing a conversion step between the JSON information and the NSData object?

if(args[@"attachments"][@"vcf"]){


NSArray *vCard = [RCTConvert  NSArray:args[@"attachments"][@"vcf"]];
    NSLog(@"%@", vCard);

    NSError *error = nil;

    NSData *data = [NSJSONSerialization dataWithJSONObject:vCard options:kNilOptions error:&error];
    NSLog(@"%@", data);


NSString *contactIdentifier = @"kUTTypeVCard";
NSString *contactName = [RCTConvert NSString:args[@"attachments"][@"contactName"]];

[ mcvc addAttachmentData:data typeIdentifier:contactIdentifier filename:contactName];

}

Here is the JSON Object being passed into the state:

data: "BEGIN:VCARD↵VERSION:4.0↵FN:Matthew Marks↵EMAIL;TYP…quot;];PREF=1:Matthewmarks13@gmail.com↵END:VCARD↵"

This is the NSLog of the data:

<5b224245 47494e3a 56434152 445c6e56 45525349 4f4e3a34 2e305c6e 464e3a4d 61747468 6577204d 61726b73 5c6e454d 41494c3b 54595045 3d5b2671 756f743b 776f726b 2671756f 743b2c20 2671756f 743b696e 7465726e 65742671 756f743b 5d3b5052 45463d31 3a4d6174 74686577 6d61726b 73313340 676d6169 6c2e636f 6d5c6e45 4e443a56 43415244 5c6e225d>
duwerq
  • 99
  • 9
  • What are the nil values? Is `error` nil? is `vCard` a "real" JSON object? – Larme Jun 21 '16 at 18:23
  • vCard is a JSON object in the form of an array. I'm making a call for a .vcf file and it returns the data in the form of JSON. I"m trying to the JSON back into a data object that can be attached and recognized as a vcf file. – duwerq Jun 21 '16 at 18:27
  • 1
    Your JSON object doesn't seem valid. Try to put test it on http://jsonlint.com (for instance), or at least check the `error` parameter. Or you didn't show the real "json object". – Larme Jun 21 '16 at 18:44
  • Also, your JSON seems to contain return characters: ↵. vCard requires each label to be on a new line so try replacing those ↵ with `\n` before parsing. – W.K.S Jun 21 '16 at 19:00

0 Answers0