我有这样的数据库数据。
["{37.331622, -122.030337}","{37.331593, -122.03051}","{37.331554, -122.030681}","{37.331383, -122.030757}","{37.33108, -122.030772}","{37.330798, -122.030729}","{37.330636, -122.030636}"]然后,我尝试通过以下代码从数据库中查询数据。
- (void)updateLocations {
CGFloat kilometers = self.radius/1000.0f;
//PFUser *user = [PFUser currentUser];
PFQuery *query = [PFQuery queryWithClassName:@"Session"];
[query whereKey:@"objectId" equalTo:@"t2udAri048"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
NSLog(@"objects %@",objects);
NSLog(@"path %@",[objects valueForKey:@"Path"]);
NSArray *pointsArray = [objects valueForKey:@"Path"];;
NSInteger pointsCount = pointsArray.count;
CLLocationCoordinate2D pointsToUse[pointsCount];
for(int i = 0; i < pointsCount; i++) {
CGPoint p = CGPointFromString(pointsArray[i]);
pointsToUse[i] = CLLocationCoordinate2DMake(p.x,p.y);
}
MKPolyline *myPolyline = [MKPolyline polylineWithCoordinates:pointsToUse count:pointsCount];
[self.mapView addOverlay:myPolyline];
//NSLog(@"Drawed %@",pointsArray);
}
}];
}我得到对象的值-值- objects:@“Path”
( "{37.331622,-122.030337}","{37.331593,-122.03051}","{37.331554,-122.030681}","{37.331383,-122.030757}","{37.33108,-122.030772}",“{37.33108,-122.030729}","{37.330636,-122.030636}“)
但我希望
( "{37.331622,-122.030337}","{37.331593,-122.03051}","{37.331554,-122.030681}","{37.331383,-122.030757}","{37.33108,-122.030772}",“{37.33108,-122.030729}","{37.330636,-122.030636}“)
我该怎么办?
发布于 2014-04-13 14:41:18
看起来,objects是一个由一个元素组成的数组,它是一个具有"Path“属性的对象。在这种情况下,您应该替换
NSArray *pointsArray = [objects valueForKey:@"Path"];通过
NSArray *pointsArray = [objects[0] valueForKey:@"Path"];发布于 2014-04-13 15:09:07
在您的示例中,您有了objectId。如果是这样的话,就使用getObjectWithId。这将只返回您想要的对象。
PFQuery *query = PFQuery queryWithClassName:@"Session";
查询getObjectWithId:@"hr46gjh45";
您的示例返回一个对象数组;在本例中,数组只有一个对象(但它仍然是一个数组)。在这种情况下,必须首先从数组中检索对象。
https://stackoverflow.com/questions/23043977
复制相似问题