2

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.

2
  • So.. you want all the objects, not the dictionaries? Commented Dec 19, 2012 at 21:40
  • Are you asking how to use a JSON library in cocoa or something else? It's far from clear. Commented Dec 19, 2012 at 21:54

1 Answer 1

10

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.