gpt4 book ai didi

ios - 我不能用 JSONHTTPClient 发送参数数组吗?

转载 作者:行者123 更新时间:2023-11-29 00:41:45 25 4
gpt4 key购买 nike

我正在尝试发送一些参数:一个 NSString 和一个 NSarray。

当我打印此内容时,NSArray 具有以下格式:

(54,

55)

但是当我将其添加到 JSONHTTPClient 的参数中时,我收到此错误:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request parameters can be only of NSString or NSNumber classes.

我的代码是:

[JSONHTTPClient postJSONFromURLWithString:uploadUrl 
params:@{@"idKey":@"689769", @"idFree":myArray}
completion:^(NSDictionary *json, JSONModelError *err)

dispatch_async(dispatch_get_main_queue(), ^{

NSLog(@"complet");
});
}];

如何将数组发送到参数中?

最佳答案

如果库不支持它,那么您可能必须自己序列化它。您可以为此使用 NSJSONSerialization 类: https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSJSONSerialization_Class/#//apple_ref/occ/clm/NSJSONSerialization/dataWithJSONObject:options:error :

NSError *error = nil;
NSData *data = [NSJSONSerialization dataWithJSONObject:myArray options:kNilOptions error:&error];
NSString *myString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

现在你有了 myString 而不是 myArray 所以它应该很高兴!

关于ios - 我不能用 JSONHTTPClient 发送参数数组吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39308687/

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