JSON Data with non-standard characters causing fail....

835 views
Skip to first unread message

Jef A.

unread,
Oct 16, 2013, 11:53:23 PM10/16/13
to meetu...@googlegroups.com
I am pulling in all of the group members of a group into my ios app and i am getting the error below when NSJSONSerialization hits the following name "NÆTiV". My code errors out at page 144, if i stop at 143 it returns the data properly. Is there a way to tell my app to skip/ignore non standard characters?





ERROR:

Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Unable to convert data to string around character 176543.) UserInfo=0xa070b90 {NSDebugDescription=Unable to convert data to string around character 176543.}

mike castleman

unread,
Oct 17, 2013, 12:38:56 AM10/17/13
to meetu...@googlegroups.com
hi Jef,

If you send this header with your request:
Accept-Charset: utf-8
then the Meetup API should return data in the UTF-8 encoding. I don't
know much about iOS or NSJSON, but hopefully it should be able to handle
UTF-8 without a problem.

cheers,
mlc

On 10/16/2013 11:53 PM, Jef A. wrote:
> I am pulling in all of the group members of a group into my ios app and
> i am getting the error below when NSJSONSerialization hits the following
> name "NÆTiV". My code errors out at page 144, if i stop at 143 it
> returns the data properly. Is there a way to tell my app to skip/ignore
> non standard characters?

--
mike castleman
android developer, meetup
mailto:m...@meetup.com

Jef A.

unread,
Oct 17, 2013, 7:52:06 PM10/17/13
to meetu...@googlegroups.com
The default charset is UTF-8 but i will try explicitly setting it and also try playing with oter character sets to see what works. Thanks for your help.

Jef A.

unread,
Oct 17, 2013, 8:20:38 PM10/17/13
to meetu...@googlegroups.com
Just a follow up to help others...

The following code worked after i explicitly defined the encoding.

 

NSString *string = [NSString stringWithContentsOfURL:[NSURL  URLWithString:@"http://api.meetup.com/2/members?group_id=3780722&order=name&offset=0&format=json&page=250&key=173e4c3f7e91773332386125a521e" ] encoding:NSISOLatin1StringEncoding error:&error];

NSData *jsonData = [string dataUsingEncoding:NSUTF8StringEncoding];

NSError *error2 = nil;

self.groupMembers = [NSMutableArray array];

NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error2];

 NSArray *jsonMembersArray = [dataDictionary objectForKey:@"results"];

Reply all
Reply to author
Forward
0 new messages