如何将数据从Parse.com存储到iOS中的Sqlite DataBase?

时间:2014-04-22 10:53:52

标签: ios sqlite parse-platform objective-c-blocks

我正在使用parse.com来获取如下所示的数据。我已经使用sqlite manager创建了数据库。

- (IBAction)button:(id)sender {
    PFQuery *postQuery = [PFQuery queryWithClassName:@"movie"];

    //movie is the class name in the parse.com in that two columns store the data
    [postQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {
            //Save results and update the table
            self.postArray = objects;
            NSLog(@"array....%@",self.postArray);
            //  [spinner startAnimating];
            [self.myTable reloadData];
        }
    }];
}

- (void)getTheData:(id)sender {
    //it is sqlite query class
    model=[[DataModel alloc]init];

    //here insertQuery method to send the columns class object(buk).

    [model insertInformIntoDB:buk];

    PFObject *post = [self.postArray objectAtIndex:indexPath.row];

    NSLog(@"posttttt......%@",post);

    //here parse.com column name to send the data into sqlite Columns
    buk.name=[post objectForKey:@"name"];
    buk.Hero=[post objectForKey:@"Hero"];
}

我得到了这样的输出:

//这是整体电影类

array....(
    "<movie:EHx3UonJmw:(null)> {\n    Hero = Mahesh;\n    name = pokiri;\n    num = 222;\n}",
    "<movie:zekgTzIsLs:(null)> {\n    Hero = pawan;\n    name = jhoni;\n    num = 412;\n}",
    "<movie:0z3ZkI4lvB:(null)> {\n    Hero = Prabhas;\n    name = darling;\n    num = 312;\n}"
)

posttttt......<movie:EHx3UonJmw:(null)> {
    Hero = Mahesh;
    name = pokiri;
    num = 222;
}

错误: -

 Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSMutableString stringWithUTF8String:]: NULL cString'    

但是这里在buk.name和Hero中确定空值....

1 个答案:

答案 0 :(得分:0)

你的问题很混乱,但我仍然想表明可能出错的地方, [model insertInformIntoDB:buk];应位于设置buk变量属性的方法的末尾

-(void)getTheData:(id)sender{
  //it is sqlite query class
  model=[[DataModel alloc]init];

  //here insertQuery method to send the columns class object(buk).

  //inserting the buk without setting the values, so move this statement at the end
  //[model insertInformIntoDB:buk];


  PFObject *post = [self.postArray objectAtIndex:indexPath.row];

  NSLog(@"posttttt......%@",post);

  //here parse.com column name to send the data into sqlite Columns
  buk.name=[post objectForKey:@"name"];
  buk.Hero=[post objectForKey:@"Hero"];

  //save the buk
  [model insertInformIntoDB:buk];
}