嗨,我正在创建一个带有代码的JSON请求及其完美工作:
for (int i=0; i<= [urls count]-1; i++) {
self.items=[[NSMutableDictionary alloc] init];
[self.items setObject:[names objectAtIndex:i] forKey:@"results"];
[self.items setObject:[urls objectAtIndex:i] forKey:@"URL"];
[self.list addObject:_soccerList];
}
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:_list
options:0
error:&error];
self.results=[NSJSONSerialization
JSONObjectWithData:jsonData
options:0
error:&error];
,但是,我想将此标头添加到我要添加物品的JSON请求中。任何人都知道我该怎么做?
{
"resultCount":50,
"results": [
/// json content
]
}
我将非常感谢您的帮助。
您可以这样做:
NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"50", @"resultCount", _list1, @"results", nil];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict
options:0
error:&error];
in for loop for Line添加_soccerlist之前,添加以下行
NSDictionary *dic=[[NSDictionary alloc] initWithObjectsAndKeys:[self.items count],@"resultCount",nil];
[self.list addObject:dic];