繁体   English   中英

Parse.com数据在iOS中获取“ NULL”值

[英]Parse.com data fetch `NULL` value in iOS

我是parse.com的新手,并尝试了更多时间从中获取数据,但每次都提供NULL值。 在这里,在我的Parse表中包含1.89k行,因此我想检查所有行并从中获取数据。 对于数据获取,我编写了如下代码

-(void)getdata
{
NSMutableArray *allObjects = [[NSMutableArray alloc]init];
NSUInteger limit = 1000;
__block NSUInteger skip = 0;
PFQuery *query = [PFQuery queryWithClassName:@"MapInfo"];
[query whereKey:@"Type" equalTo:@"Business"];
[query whereKey:@"Admin" equalTo:self.bisusername];
[query setLimit: limit];
[query setSkip: skip];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (!error) {
        [allObjects addObjectsFromArray:objects];
        if (objects.count == limit) {
            skip += limit;
            [query setSkip: skip];
            [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
                [allObjects addObjectsFromArray:objects];
                self.qpinname=[allObjects valueForKey:@"GPIN"];
                NSLog(@"Qpin Array %lu",(unsigned long)[self.qpinname count]);
                self.locationArray=[allObjects valueForKey:@"Location"];
                self.latitude=[self.locationArray valueForKey:@"lat"];
                self.longitude=[self.locationArray valueForKey:@"lng"];
                self.address=[allObjects valueForKey:@"Address"];
                self.usernameArray=[allObjects valueForKey:@"AddedBy"];
                self.buildingNameArray=[allObjects valueForKey:@"BuildingName"];
                self.businessHourArray=[allObjects valueForKey:@"OfficeTiming"];
                self.parkingInfoArry=[allObjects valueForKey:@"Parking"];
                self.officenoArray=[allObjects valueForKey:@"DoorNumber"];
                NSLog(@"Office Array %@",self.officenoArray);
              hudView.hidden=TRUE;
            }];
        }
    }
    else
    {
        NSLog(@"Error: %@ %@", error, [error userInfo]);
    }
}];
}

当我写像这样的代码

-(void)getdata
 {
PFQuery *query = [PFQuery queryWithClassName:@"MapInfo"];
[query whereKey:@"Type" equalTo:@"Business"];
[query whereKey:@"Admin" equalTo:self.bisusername];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (!error)
    {
        self.qpinname=[objects valueForKey:@"GPIN"];
        self.locationArray=[objects valueForKey:@"Location"];
        self.latitude=[self.locationArray valueForKey:@"lat"];
        self.longitude=[self.locationArray valueForKey:@"lng"];
        self.address=[objects valueForKey:@"Address"];
        self.usernameArray=[objects valueForKey:@"AddedBy"];
        self.buildingNameArray=[objects valueForKey:@"BuildingName"];
        self.businessHourArray=[objects valueForKey:@"OfficeTiming"];
        self.parkingInfoArry=[objects valueForKey:@"Parking"];
        self.officenoArray=[objects valueForKey:@"DoorNumber"];
    }
    else
    {
        NSString *errorString = [[error userInfo] objectForKey:@"error"];
        NSLog(@"Error: %@", errorString);
    }
}];
}

然后我从表中获得了价值,但它仅从我要从整个表中获得价值的一页就给了我价值,请给我解决方案。

您根本不需要迭代对象数组。 您正在执行以下操作:

self.qpinname=[allObjects valueForKey:@"GPIN"];

allObjects是一个ARRAY而不是一个字典。 您需要迭代数组并以这种方式访问​​对象。 请记住,对象是从Parse.com下载的PFObject类型。 例如:

[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
                [allObjects addObjectsFromArray:objects];
                for(PFObject *object in allObjects) {

                //now you can access things,e.g....
                self.locationArray=object[@"Location"]; 
                //and so on...



               }

            }];

那应该解决它。 确保在循环中也使用上面的PFObject。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM