提问人:stefanosn 提问时间:10/22/2021 最后编辑:stefanosn 更新时间:10/22/2021 访问量:57
NSInvalidArgumentException:Json 写入目标 c 中的类型无效
NSInvalidArgumentException Invalid type in Json write objective c
问:
我是目标 c 的新手。我在以下行的 Json write (NSError) 中得到 NSInvalidArgumentException Invalid type。
NSURLSessionDataTask *result = [self POST:@"/analytics"
parameters:params completion:^(OVCResponse * _Nullable response, NSError * _Nullable error) {
[self handleResponse:response error:error adjustErrorBlock:self.commonErrorAdjustBlock completion:theCompletion];
}];
代码如下
NSArray *params = [MTLJSONAdapter JSONArrayFromModels:events error:NULL];
void(^theCompletion)(id _Nullable, NSError * _Nullable) = ^(id _Nullable result, NSError * _Nullable error) {
completion(error);
};
NSURLSessionDataTask *result = [self POST:@"/analytics/"
parameters:params completion:^(OVCResponse * _Nullable response, NSError * _Nullable error) {
[self handleResponse:response error:error adjustErrorBlock:self.commonErrorAdjustBlock completion:theCompletion];
}];
HandleResponse 方法
- (void)handleResponse:(nullable OVCResponse *)response error:(nullable NSError *)error adjustErrorBlock:(nullable C8ApiClientv2AdjustErrorBlock)adjustErrorBlock completion:(void (^)(id _Nullable result, NSError * _Nullable error))completion {
DebugLog(@"\n===[start response] <%@> \n===%@, \nerror:%@\n===[end response] <%@> ", self.class, response, error, self.class);
NSError *adjustedError = nil;
if (NULL != adjustErrorBlock){
adjustedError = adjustErrorBlock(error, response);
}
if (nil != adjustedError) {
completion(nil, adjustedError);
} else {
if (response.HTTPResponse.statusCode >= 200 && response.HTTPResponse.statusCode <= 299) {
NSAssert(error == nil, @"got error though request succeded");
}
else if (response.HTTPResponse.statusCode == 401) {
error = NSError.com_eight_APIServiceUnauthorizedError;
}
else if (response.HTTPResponse.statusCode >= 500 && response.HTTPResponse.statusCode <= 599) {
error = nil != error ? error : NSError.com_eight_APIServiceUnknownError;
[SentrySDK captureMessage:[NSString stringWithFormat:@"Request failed: internal server error (500):\n%@", response]];
}
else {
error = nil != error ? error : NSError.com_eight_APIServiceUnknownError;
}
id result = nil == error ? response.result : nil;
completion(result, error);
}
}
跟踪
-[AFJSONRequestSerializer requestBySerializingRequest:withParameters:error:]
(AFNetworking/AFNetworking/AFURLRequestSerialization.m:1312)
8
+0x01f480
-[AFHTTPRequestSerializer requestWithMethod:URLString:parameters:error:]
(AFNetworking/AFNetworking/AFURLRequestSerialization.m:407)
8
+0x161de8
-[OVCHTTPSessionManager _dataTaskWithHTTPMethod:URLString:parameters:completion:]
(Overcoat/sources/Core/OVCHTTPSessionManager.m:74)
8
+0x1621f0
-[OVCHTTPSessionManager POST:parameters:completion:]
(Overcoat/sources/Core/OVCHTTPSessionManager.m:129)
8
+0x42d98c
-[C8AnalyticsClientv2 trackEvents:completion:]
(DAL/Networkingv2/Clients/C8AnalyticsClientv2.m:40)
任何帮助都表示赞赏。
答: 暂无答案
评论
NSJSONSerialization
JSONArrayFromModels
POST:parameters:completion: