在Xcode中收到一个引用错误,说明一个对象没有定义
Receiving a reference error in Xcode stating that an object is not defined.
我正在编写解析云代码,该代码ping eBay,返回带有项目结果的JSON数据,然后解析该数据并将前两个类别存储到数组中。发送到eBay的查询是基于用户在我的iOS应用程序的itemSearch栏中输入的任何内容。当我尝试发送像"iPhone"这样的查询时,它会给我一个错误,说明如下:
ReferenceError: data is not defined
at Object.Parse.Cloud.httpRequest.success (main.js:34:11)
at Object.<anonymous> (<anonymous>:565:19) (Code: 141, Version: 1.2.18)
objective-c代码如下:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if (sender != self.nextButton) return;
if (self.itemSearch.text.length > 0) {
[PFCloud callFunctionInBackground:@"eBayCategorySearch"
withParameters:@{@"item": self.itemSearch.text}
block:^(NSString *result, NSError *error) {
if (!error) {
NSLog(@"Successfully pinged eBay!");
}
}];
}
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
运行在Parse上的云代码(main.js)如下:
Parse.Cloud.define("eBayCategorySearch", function(request, response) {
url = 'http://svcs.ebay.com/services/search/FindingService/v1';
Parse.Cloud.httpRequest({
url: url,
params: {
'OPERATION-NAME' : 'findItemsByKeywords',
'SERVICE-VERSION' : '1.12.0',
'SECURITY-APPNAME' : '*APP ID GOES HERE*',
'GLOBAL-ID' : 'EBAY-US',
'RESPONSE-DATA-FORMAT' : 'JSON',
'itemFilter(0).name=ListingType' : 'itemFilter(0).value=FixedPrice',
'keywords' : request.params.item,
// your other params
},
success: function (httpResponse) {
response.success(httpResponse.data)
// count number of times each unique primaryCategory shows up (based on categoryId), return top two (done with a for loop?)
var userCategories = {};
data.findItemsByKeywordsResponse.searchResult[0].item.forEach(function(item)
{
var id = item.primaryCategory[0].categoryId;
if (userCategories[id]) userCategories[id]++;
else userCategories[id] = 1;
});
var top2 = Object.keys(userCategories).sort(function(a, b)
{return userCategories[b]-userCategories[a]; }).slice(0, 2);
console.log('Top two categories: ' + top2.join(', '));
// deal with success and respond to query
},
error: function (httpResponse) {
console.log('error!!!');
console.error('Request failed with response code ' + httpResponse.status);
}
});
});
我相信这可能是因为JSON没有被正确返回,但我不确定我将如何确保,或者如何修复。任何帮助都是感激的!
第一步记录httpResponse对象的值。更新您的success
回调以记录值:
success: function (httpResponse) {
console.log('Received successful response.'); // <---
console.log(httpResponse); // <---
response.success(httpResponse.data)
// count number of times each unique primaryCategory shows up (based on categoryId), return top two (done with a for loop?)
var userCategories = {};
data.findItemsByKeywordsResponse.searc
你可以在这里阅读如何记录数据:https://parse.com/docs/cloud_code_guide#logging
您可以在这里找到更多关于阅读日志的信息:https://parse.com/docs/cloud_code_guide#clt-logs
相关文章:
- gmaps4rails 2.4.6未捕获引用错误:未定义Gmaps
- Wordpress中的Javascript出现匿名函数/引用错误
- 使用dc.js、d3.js和crossfilter引用错误
- 未捕获引用错误:未定义validateform
- 为什么我会出现此错误"未捕获引用错误:未定义标题;
- $未定义-未捕获引用错误
- Sitecore”;未捕获引用错误:未定义MultilistWithSearch;
- Wordpress:未捕获引用错误:未定义速度
- Node.js引用错误:未定义类名
- 我该如何解决“;未捕获引用错误:谷歌没有定义"?(谷歌地图API)
- Javascript 未定义错误:引用错误:未定义 ALT
- 为流星重新包装砌体会产生错误“引用错误:窗口未定义”
- 未定义错误引用
- 错误: 引用错误: 未定义发送
- 角度砌体指令隐藏内部元素,错误:引用错误:未定义砌体
- CoffeeScript 在 'for v in values' 中创建一个全局变量 'v',导致事件中的错误引用
- Javascript:未捕获类型错误:引用创建的对象时无法调用未定义的方法“add”
- 架构错误 - 引用错误:未定义电话
- 获取错误“引用错误:未定义事件”
- 打字稿错误引用_this