简体   繁体   English

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

[英]How to store the Data from Parse.com to Sqlite DataBase in iOS?

I am using parse.com to get the data like given below. 我正在使用parse.com来获取如下所示的数据。 I already created the data base using sqlite manager. 我已经使用sqlite管理器创建了数据库。

- (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"];
}

I got the output like this: 我得到这样的输出:

//this is overall movie class //这是整体电影课

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;
}

Error:- 错误:-

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

but here geting null values in buk.name and Hero.... 但是这里在buk.name和Hero中获得了空值。

You question is so confusing but still I would love to show what might be wrong, [model insertInformIntoDB:buk]; 您的问题是如此令人困惑,但我仍然想表明可能出什么问题, [model insertInformIntoDB:buk]; should be at the end of the method where you set the properties of the buk variable 应该在您设置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];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM