Im trying to create a json array out of nsmutable array.
To do so, Im trying to convert nsmutable array to nsdata as follows,
NSData *dataArray = [NSKeyedArchiver archivedDataWithRootObject:self.countryNameArray];
self.countryNameArray is a mutable array that contains names of countries.
Then Im trying to create a json array out of NSData as follows
NSString* jsonArray = [[NSString alloc] initWithBytes:[dataArray bytes] length:[dataArray length] encoding:NSUTF8StringEncoding];
but the problem is that, jsonArray is null when Im trying to use it.
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:arr options:NSJSONWritingPrettyPrinted error:&error];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With