gpt4 book ai didi

ios - 如何在ios中将包含字典的数组发送到服务器?

转载 作者:行者123 更新时间:2023-11-29 03:38:48 25 4
gpt4 key购买 nike

嗨,我想将一组数据发送到服务器数组,例如

{ FeedStats: [{
FeedId: 1,
FeedIndex: 1,
},
{
FeedId: 2,
FeedIndex: 21,
}]}

我正在尝试使用 afnetworking

 NSMutableArray *tempArray = [[NSMutableArray alloc]init];
NSDictionary *tempDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
currentPerson.feedId, @"FeedId",
currentPerson.articleIndex, @"FeedIndex",
nil];
NSDictionary *tempDictionary1 = [NSDictionary dictionaryWithObjectsAndKeys:
currentPerson1.feedId, @"FeedId",
currentPerson1.articleIndex, @"FeedIndex",
nil];
[tempArray addObject:tempDictionary];
[tempArray addObject:tempDictionary1];

NSDictionary *tempDict = [[NSDictionary alloc]initWithObjectsAndKeys:tempArray,@"FeedStats", nil];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://xxx.xx/"]];
[httpClient setAuthorizationHeaderWithToken:authToken];
[httpClient setDefaultHeader:@"Content-Type" value:@"application/json"];

[httpClient postPath:@"xx/xxx" parameters:tempDict success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSString *responseStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
NSLog(@"Request Successful, response '%@'", responseStr);

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"[HTTPClient Error]: %@", error.localizedDescription);
}];

但是服务器中的数组将变为空

FeedStats:[] 

如何解决这个问题

最佳答案

改变:

NSDictionary *tempDict = [[NSDictionary alloc]initWithObjectsAndKeys:tempReportArray,@"FeedStats", nil];

收件人:

NSDictionary *tempDict = [[NSDictionary alloc]initWithObjectsAndKeys:tempArray,@"FeedStats", nil];

tempReportArray => tempArray

关于ios - 如何在ios中将包含字典的数组发送到服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18764199/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com