+ Start a Discussion

Can't deserialize date fields?

I am working on an iOS app procedure that queries a SQLite database and attempts to upload the records onto SalesForce. However, I seem to be having issues with the date fields. I keep getting an error message that it cannot be serialized. My JSON-savvy coworker suggested I try using the ASCII notation to represent the "/" in the dates, but it still keeps giving me the same error. How do I format the StartDate field so SalesForce will accept it?


 if (sqlite3_prepare_v2(database, [query UTF8String],-1,&statement, nil) ==SQLITE_OK)
        while (sqlite3_step(statement) == SQLITE_ROW)

NSDate* MyDate = [formatter dateFromString: [NSString stringWithCString (char*)sqlite3_column_text(statement, 2) encoding:NSUTF8StringEncoding]];

NSMutableString * StartDate = [NSMutableString stringWithFormat:@"%@",[formatter stringFromDate:MyDate]];

 [StartDate replaceCharactersInRange: [StartDate rangeOfString:@"/"] withString:@"&#48" ];

 [StartDate replaceCharactersInRange: [StartDate rangeOfString:@"/"] withString:@"&#48" ]; //Other fields, irrelevant code to problem
NSDictionary * fields = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects: [NSNumber numberWithInt:FormID],AuditID,StartDate,StartTime,StationID,UserID,Gate,FlightNumber,RegNoseNumber,Completed,Year,AirCraft, nil] forKeys:[NSArray arrayWithObjects: @"FormID__c",@"AuditID__c",@"StartedDate__c",@"StartedTime__c",@"StationID__c",@"UserID__c",@"Gate__c",@"FlightNumber__c",@"RegistryNoseNumber__c",@"Completed__c",@"Year__c",@"Aircraft__c", nil] ]; SFRestRequest *request = [[SFRestAPI sharedInstance] requestForCreateWithObjectType:@"Form__c" fields:fields]; [[SFRestAPI sharedInstance] send:request delegate:self]; } sqlite3_finalize(statement); sqlite3_close(database);



date / datetimes should be in iso 8601 format, e.g. 2012-05-14T20:21:00Z


I still keep getting the failure : (


5/17/12 8:18:15.487 AM SOSApp SF: error: Error Domain=com.salesforce.RestAPI.ErrorDomain Code=999 "The operation couldn’t be completed. (com.salesforce.RestAPI.ErrorDomain error 999.)" UserInfo=0x6ea6870 {message=Cannot deserialize instance of date from VALUE_STRING value 2012-05-17T07:47-0500 at [line:9, column:45], errorCode=JSON_PARSER_ERROR}


what is the date format you've applied to your NSDateFormatter?


on an unrelated note: why are you using Sqlite directly instead of core data?


It's my intention to learn Core Data after this project. I've only been programming on iOS for a few months but had to meet pressing development deadlines for the app while I learned.






    NSDateFormatter *formatter;
    formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-ddTHH:mmZ"];




Your date formatter format is missing parameters for seconds and miliseconds. Are you sure the ISO 8601 standard will accept that format? 


Well until now I haven't really given much thought to the ISO 8601 format. What format syntax would you suggest I put in the formatter? I'm just trying to get SalesForce to accept the silly thing.


Try this man,


    //set Date formatter

    NSTimeInterval startDateSeconds = [[NSDate yourDaaaaaaaaaaaaaaate] timeIntervalSince1970];

    NSDate *startDate = [NSDate dateWithTimeIntervalSince1970:startDateSeconds];


    NSDateFormatter* df_utc = [[[NSDateFormatteralloc] init] autorelease];

    [df_utc setTimeZone:[NSTimeZonetimeZoneWithName:@"UTC"]];

    [df_utc setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.000'Z'"];


    NSString *startDateString = [df_utc stringFromDate:startDate];