[英]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.