Objective c 当使用obj c将数据发布到parse.com时,我得到的响应为code=107 error=";无效的json:";
当我试图通过NsMutableUrlRequest将url发布到Parse.com时,得到的响应如下 代码=107; error=“无效json:” 该函数是用javaScript编写的 但是当我从curl发帖时,我得到了确切的输出Objective c 当使用obj c将数据发布到parse.com时,我得到的响应为code=107 error=";无效的json:";,objective-c,json,curl,parse-platform,nsmutableurlrequest,Objective C,Json,Curl,Parse Platform,Nsmutableurlrequest,当我试图通过NsMutableUrlRequest将url发布到Parse.com时,得到的响应如下 代码=107; error=“无效json:” 该函数是用javaScript编写的 但是当我从curl发帖时,我得到了确切的输出 curl -X POST \ -H "X-Parse-Application-Id: appID" \ -H "X-Parse-REST-API-Key: restAPiKEy" \ -H "Content-Type: application/js
curl -X POST \
-H "X-Parse-Application-Id: appID" \
-H "X-Parse-REST-API-Key: restAPiKEy" \
-H "Content-Type: application/json" \
-d '{}' \
但在目标c中,我得到了错误
这是我的密码
NSURL *URL = [NSURL URLWithString:@"https://api.parse.com/1/functions/hello"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
request.HTTPMethod = @"POST";
NSString * params = @"----the app id---=X-Parse-Application-Id&-----the rest api key=X-Parse-REST-API-Key";
NSData *data = [params dataUsingEncoding:NSUTF8StringEncoding];
[request setValue:@"APPID" forHTTPHeaderField:@"X-Parse-Application-Id"];
[request setValue:@"REST API KEY" forHTTPHeaderField:@"X-Parse-REST-API-Key"];
[request addValue:@"8bit" forHTTPHeaderField:@"Content-Transfer-Encoding"];
[request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request addValue:[NSString stringWithFormat:@"%lu", (unsigned long)[data length]] forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:data];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Peform the request
NSURLResponse *response;
NSError *error = nil;
NSData *receivedData = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&error];
NSDictionary *dictOfNews = [NSJSONSerialization
JSONObjectWithData:receivedData //1
options:kNilOptions
error:&error];
NSLog(@"dict of the news: %@", dictOfNews);
if (error) {
// Deal with your error
if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
NSLog(@"HTTP Error: %ld %@", (long)httpResponse.statusCode, error);
return;
}
NSLog(@"Error %@", error);
}
else
{
NSLog(@"SUCCESS GRAND SUCCESS");
}
});
请告诉我,我哪里做错了。提前感谢我只是好奇你为什么要这么做,有一个原生的Objective-C API为你包装了其余的调用@TimothyWalters我正在使用你提到的url保存和获取对象,但这是用javascript编写的云代码(),要获取数据,有没有其他方法在Xcode中获取“”[PFCloud callFunctionInBackground:@“hello”with Parameters@{}block:…]@TimothyWalters非常感谢。这非常有效而且非常简单。。