AFNetworking POST崩溃

时间:2016-03-04 14:24:06

标签: ios objective-c json afnetworking-2

我试图将json字符串发布为NSString。但是在发布请求时Xcode崩溃并打印:" JSON写入中的顶级类型无效"。这是我的代码:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];


[manager POST:signupBaseURLString parameters:myJSONStringObject success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"responseObject is %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"post request error is %@", error);
}];

1 个答案:

答案 0 :(得分:0)

参数应该是NSDictionary,而不是字符串。我假设myJSONStringObject是一个字符串。如果字符串是JSON对象的编码,则需要将其转换回字典,或者最好使用您编码的字典。