【发布时间】:2014-05-03 08:44:52
【问题描述】:
我有一个卷号数组
NSArray *rollArray = [NSArray arrayWithObjects:@"1", @"22", @"24", @"11", nil];
我需要在 Web 服务请求中发送这个数组
它的格式是这样的(JSON格式)
JSON 数据
{
"existingRoll":["22","34","45","56"], // Array of roll numbers
"deletedRoll":["20","34","44","56"] // Array of roll numbers
}
但我在将滚动数字数组 (rollArray) 转换为 json 字符串时遇到问题 以所需的格式。
我正在尝试这个
NSMutableDictionary *postDict = [[NSMutableDictionary alloc]init];
[postDict setValue:[rollArray componentsJoinedByString:@","] forKey:@"existingRoll"];
NSString *str = [Self convertToJSONString:postDict]; // converts to json string
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:str options:0 error:nil];
[request setHTTPBody:jsonData];
我使用的是 iOS 7
【问题讨论】:
-
你能添加导致问题的代码吗?还有什么问题?
-
NSDictionary 已通过 NSJSONSerialization 成功转换为 JSON 格式/从 JSON 格式转换。请检查我的答案。
标签: ios objective-c json cocoa nsarray