title: how to insert and save json array into sqlite ios
body: <pre><code>-(BOOL)createDB{
  NSString *docsDir;
  NSArray *dirPaths;
  dirPaths = NSSearchPathForDirectoriesInDomains
  (NSDocumentDirectory, NSUserDomainMask, YES);
  docsDir = dirPaths[0];
  databasePath = [[NSString alloc] initWithString:
                  [docsDir stringByAppendingPathComponent: @"oiwii.db"]];
  BOOL isSuccess = YES;
  NSFileManager *filemgr = [NSFileManager defaultManager];
  if ([filemgr fileExistsAtPath: databasePath ] == NO)
  {
      const char *dbpath = [databasePath UTF8String];
      if (sqlite3_open(dbpath, &amp;database) == SQLITE_OK)
      {
          char *errMsg;
          const char *sql_stmt ="create table if not exists jsonData (status text, message text,  mood_name text, description text, c1 text, c2 text c3 text, c4 text, c5 text, font_name text, font_size text, font_color text)";
          if (sqlite3_exec(database, sql_stmt, NULL, NULL, &amp;errMsg)!= SQLITE_OK)
          {
              isSuccess = NO;
              NSLog(@"Failed to create table");
          }
          sqlite3_close(database);
          return  isSuccess;
      }
      else {
          isSuccess = NO;
          NSLog(@"Failed to open/create database");
      }
  }
  return isSuccess;
  </code></pre>
  
  <p>}</p>
  
  <p>i have created a database above and i am trying to add the json object(array) into my sqlite.
  my json object looks like this- 
  {"moods_name":"mood2","description":"this is mood 2","c1":"D4FF38","c2":"FFA83D","c3":"FFFA9E","c4":"66FFBA","c5":"63FFE8","font_name":"Default","font_size":"10","font_color":"363636"}
  and i want to fetch this array</p>
  
  <pre><code>-(BOOL)saveData:(NSString *)status message:(NSString *)message mood_name:(NSString *)mood_name description:(NSString *)description c1:(NSString *)c1 c2:(NSString *)c2 c3:(NSString *)c3 c4:(NSString *)c4 c5:(NSString *)c5 font_name:(NSString *)font_name font_size:(NSString *)font_size font_color:(NSString *)font_color{
  
  const char *dbpath = [databasePath UTF8String];
  if (sqlite3_open(dbpath, &amp;database) == SQLITE_OK)
  {
      NSString *insertSQL = [NSString stringWithFormat:@"insert into jsonData (status,message, description, c1,c2,c3,c4,c5,font_name,font_size,font_color) values (\"%@\",\"%@\", \"%@\", \"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\")",status, message, description, c1,c2,c3,c4,c5,font_name,font_size,font_color];
      const char *insert_stmt = [insertSQL UTF8String];
      sqlite3_prepare_v2(database, insert_stmt,-1, &amp;statement, NULL);
      if (sqlite3_step(statement) == SQLITE_DONE)
      { NSLog(@"data saved");
          return YES;
  
      }
      else {
          return NO;
      }
  
  }
  
  sqlite3_reset(statement);
  return NO;
  </code></pre>
  
  <p>}</p>
  
  <p>update:
  code to fetch data </p>
  
  <pre><code>-(void)fetchdata
  {
  arrayfetched = [[NSMutableArray alloc] init];
  
  // Setup the database object
  sqlite3 *database;
  
  // Open the database from the users filessytem
  if(sqlite3_open([databasePath UTF8String], &amp;database) == SQLITE_OK)
  {
  
      //SQLIte Statement
      NSString *sqlStatement_userInfo =[NSString stringWithFormat:@"Select * from moodsdata"];
  
      sqlite3_stmt *compiledStatement;
  
  
      if(sqlite3_prepare_v2(database, [sqlStatement_userInfo UTF8String], -1, &amp;compiledStatement, NULL) == SQLITE_OK)
      {
  
          // Loop through the results and add them to the fetchedarray
          while(sqlite3_step(compiledStatement) == SQLITE_ROW)
          {
              // Init the Data Dictionary
              NSMutableDictionary *_dataDictionary=[[NSMutableDictionary alloc] init];
  
              NSString *msg = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)];
  
              NSString *status = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
  
              NSString *data = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
  
              [_dataDictionary setObject:[NSString stringWithFormat:@"%@",msg] forKey:@"message"];
              [_dataDictionary setObject:[NSString stringWithFormat:@"%@",status] forKey:@"status"];
              [_dataDictionary setObject:[NSString stringWithFormat:@"%@",data] forKey:@"data"];
  
              [arrayfetched addObject:_dataDictionary];
              NSLog(@"array fetched%@",arrayfetched);
  
          }
      }
      else
      {
          NSLog(@"No Data Found");
      }
  
      // Release the compiled statement from memory
      sqlite3_finalize(compiledStatement);
  }
     sqlite3_close(database);
  NSLog(@" fetched array%@",arrayfetched);
  }
  </code></pre>
  
  <p>please help me.</p>