我试图将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);
}];
答案 0 :(得分:0)
参数应该是NSDictionary,而不是字符串。我假设myJSONStringObject
是一个字符串。如果字符串是JSON对象的编码,则需要将其转换回字典,或者最好使用您编码的字典。