所以我对此比较陌生,而且我遇到了一个让我很难过的问题。 SimpleUPC提供了一个非常简单的API,但它们具有以下JSON请求格式:
{
"auth":"Your API Key",
"method":"MethodName",
"params": {
"paramName":"paramValue",
"paramName2":"paramValue2",
},
"returnFormat":"optional"
}
我还下载了他们已验证的Ruby样本,它可以在命令行中运行。
# Sample API calls using JSON...
host = "api.simpleupc.com"
path = "/v1.php"
# An example query for FetchProductByUPC method
request = {
"auth" => 'Your-API-Key',
"method" => 'FetchProductByUPC',
"params" => {"upc" => '041383096013'}
}
json = request.to_json()
response = Net::HTTP.start(host) { |http|
http.post(path, json, initheader = {'Content-Type' =>'text/json'})
}
output = response.body
puts output
好到目前为止一切顺利。但这是我的代码试图做同样的事情,但我得到错误抱怨缺少参数。
NSDictionary *requestDict = @{@"auth": kSimpleAPIKey, @"method": @"FetchProductByUPC", @"params":@{@"upc": code}};
[[SimpleUPCClient sharedClient] getPath:@""
parameters:requestDict
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Response: %@", responseObject);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[TMReportingHandler handleError:error fatal:NO];
}];
我知道这必须是简单的我做错了但我无法弄明白。任何人吗?
答案 0 :(得分:0)