-2

Possible Duplicate:
separating keys and objects from NSMutable dictionary and use the values in insert command of sqlite

I have an NSDictionary containing parsed JSON data. How can I push these data to a database so that I can extract them from database for further use?

I am using SBJSON for parsing.

Community
  • 1
  • 1
Avi
  • 45
  • 1
  • 7
  • 1
    check this question and check out the code in accpeted answer i think it may help you http://stackoverflow.com/questions/5677396/separating-keys-and-objects-from-nsmutable-dictionary-and-use-the-values-in-inser – B25Dec Oct 10 '11 at 10:32

3 Answers3

2

If your design requirements specify sqlite, then I would recommend using Gus Mueller's FMDB so that you do not have to work directly with raw sqlite.

NSString $title = [jsonDictionary objectForKey:@"title"];
//  other keys, values, etc...
NSString $query = [NSString stringWithFormat:@"INSERT INTO myTable t (t.some_column) VALUES ('%@'),$title];
FMResultSet *results = [_db executeQuery:$query];

That said, as Chris said above, Core Data is often a better solution than sqlite. Brent Simmons (NetNewsWire developer) has a series of posts about this subject, like this one.

The exception to the "Core Data is better than sqlite" mantra for me is the situation where you want to provide initial data but do not want to perform an initial import into Core Data.

FluffulousChimp
  • 9,157
  • 3
  • 35
  • 42
  • I have something like this, NSDictionary *myDict = [NSDictionary alloc]init]; NSString *jsonString = @"Json response...."; myDict = [jsonString JSONValue]; I need to write the contents of myDict into database. I am using SqlLite as my app demands this. Please help me with a solution. – Avi Oct 10 '11 at 11:17
0

Use core data for this matter. Here is a good tutorial to start with: http://mobile.tutsplus.com/tutorials/iphone/iphone-core-data/

Chris
  • 117
  • 1
  • 8
0

Following code goes to create the dynamic plist file and that file stores into the bundle and that data can be access and the insert the data into the .plist file.

NSString *strPathToAudioCache=[NSString stringWithFormat:@"%@/%@",
                                           [(NSArray*)NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0],
                                           @"data.plist"];


            NSMutableDictionary *dOfAudios=[NSMutableDictionary dictionaryWithContentsOfFile:strPathToAudioCache];
            NSLog([dOfAudios allKeys].count>0?@"Value is exist":@"Value is not exist");
            if([dOfAudios allKeys].count>0) {
                [dOfAudios setValue:@"Key_for_value" forKey:@"value_for_key"];
            } else {

                dOfAudios=[NSMutableDictionary dictionary];
                [dOfAudios setValue:@"Key_for_value" forKey:@"value_for_key"];

            }
            [dOfAudios writeToFile:strPathToAudioCache atomically:YES];
Nimit Parekh
  • 16,776
  • 8
  • 50
  • 72