我需要解析一个Coulomb中的所有对象。比方说比如我在课堂上用coulombs解析:City,StreetCode,Suburb。现在我希望City下的所有对象都在一个数组中。
数组应该添加City下的所有对象:
应该返回Array:City1,City2,City3,City4等。
我发现这段代码可以获取Class中的所有对象:
PFQuery *query = [PFQuery queryWithClassName:@"StreetCodes"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error)
{
if (!error)
{
NSLog(@"%@",allObjects);
// The find succeeded. The first 100 objects are available in objects
} else
{
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
但是此代码返回:
<StreetCodes: 0x7c1d76e0, objectId: dpFuJgeRnB, localId: (null)> {\n City = KWANOBUHLE;\n StreetCode = 6242;\n Suburb = \"10TH AVENUE\";\n}",
"<StreetCodes: 0x7c638020, objectId: OE9MtOGpVd, localId: (null)> {\n City = KWANOBUHLE;\n StreetCode = 6242;\n Suburb = \"1ST AVENUE\";\n}",
"<StreetCodes: 0x7c1cf970, objectId: 16TMG5V3jS, localId: (null)> {\n City = DURBAN;\n StreetCode = 4091;\n Suburb = \"45TH CUTTING\";\n}",
"<StreetCodes: 0x7c1c1dd0, objectId: 0Vk6oav0Zt, localId: (null)> {\n City = RIVERSDALE;\n StreetCode = 6670;\n Suburb = AALWYNFLEUR;\n}",
"<StreetCodes: 0x7c1db4e0, objectId: EVYUUWzTB7, localId: (null)> {\n City = BLOEMFONTEIN;\n StreetCode = 9301;\n Suburb = AANDRUS;
这将返回添加到数组中的类中的所有对象。 我该如何使用它?因为我只想要City Coulomb对象。
请帮助或提供一些示例代码
答案 0 :(得分:0)
使用PFQuery的selectKeys
会将查询限制为仅检索您的城市数据:
[query selectKeys:@[@"City"]];
我认为这不是你想要的。您需要运行从它们中取出City
的返回对象数组:
if (!error)
{
NSMutableArray* array = [NSMutableArray arrayWithCapacity:objects.count]; // make an array to hold the cities
for(PFObject* obj in objects) {
[array addObject:[obj objectForKey:"@City"]];
}
// etc.