从解析web服务中获取保存的数据?

时间:2013-12-12 12:40:57

标签: ios iphone objective-c web-services parse-platform

我在我的iphone应用中使用Parse webservice。 我可以保存并检索帐户中的数据。

我正在获取保存的数据,如下所示 -

   -(void)Fetch{

      PFQuery *query = [PFQuery queryWithClassName:@"Gossips"];
      [query orderByDescending:@"createdAt"];
       [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (!error) {
        NSArray* wallObjectsArray = [[NSArray alloc] initWithArray:objects];
        NSLog(@"wallObjectsArray:--------- %@", wallObjectsArray);

     } else {
        NSString *errorString = [[error userInfo] objectForKey:@"error"];
        NSLog(@"Error: %@", errorString);
       }
   }];
    }

和输出 -

    wallObjectsArray:--------- "<MyApp:dPotrdMmZy> {\n    category = politics;\n    content = \"Madiba died..!!\";\n    user = john;\n}",

如何从此数组中检索不同键的每个对象。 我想知道waht是内容还是谁是用户?

2 个答案:

答案 0 :(得分:0)

尝试

for (PFObject *innerObject in objects)
{ 
  NSLog(@"WallObjects:------ %@", innerObject);

}

答案 1 :(得分:0)

我只是添加了“for”循环来获取您想要的信息,其中包含一些示例“UserName”和“Score”字段,需要在您的parse.com类中更改为什么。

希望有所帮助

-(void)Fetch{
 PFQuery *query = [PFQuery queryWithClassName:@"Gossips"];  
    [query orderByDescending:@"createdAt"];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {
          //  NSArray* wallObjectsArray = [[NSArray alloc] initWithArray:objects];
         //   NSLog(@"wallObjectsArray:--------- %@", wallObjectsArray);

            for (PFObject *info in objects) {

                NSLog(@"Id: %@", info.objectId);
                NSLog(@"User: Name %@", [info objectForKey:@"UserName"]);
                NSLog(@"Score: %@", [info objectForKey:@"Score"]);
            }
        } else {
            NSString *errorString = [[error userInfo] objectForKey:@"error"];
            NSLog(@"Error: %@", errorString);
        }
    }];

}