Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert NSArray into array of JSON objects

I'd like to create a JSON array of objects from the resultsArray.

NSMutableArray *resultsArray = [NSMutableArray array];
FMResultSet *resultsSet = [database executeQuery:queryString];
while ([resultsSet next]) {
    [resultsArray addObject:[resultsSet resultDictionary]];
}

For clarification, I'm using FMDB to query a database. I'm then storing the resulting objects within the resultsArray. From here I want to convert that results array into a JSON array of objects.

like image 968
Karoh Avatar asked Apr 25 '26 12:04

Karoh


1 Answers

You can use NSJSONSerialization class to create a JSON file from your dictionary using the class method

NSData * JSONData = [NSJSONSerialization dataWithJSONObject:resultsArray
                                                    options:kNilOptions
                                                      error:&error];

For more info look at apple documentation

like image 66
Andrew Avatar answered Apr 28 '26 03:04

Andrew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!