Convert NSArray into array of JSON objects

2019-02-25 19:54发布

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.

1条回答
欢心
2楼-- · 2019-02-25 20:49

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

查看更多
登录 后发表回答