将NSArray转换为JSON对象数组 [英] Convert NSArray into array of JSON objects

查看:126
本文介绍了将NSArray转换为JSON对象数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从resultsArray创建一个JSON对象数组。

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]];
}

为了澄清,我使用FMDB查询数据库。然后我将结果对象存储在resultsArray中。从这里我想将结果数组转换为JSON对象数组。

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.

推荐答案

您可以使用NSJSONSerialization类创建JSON使用类方法从您的字典中的文件

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

这篇关于将NSArray转换为JSON对象数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆