Search code examples
iphoneobjective-csbjson

How to parse /Date(xxx+0000)/ in SBJSON


I am trying to parse JSON with date produced by the .NET service to NSDate object

{
 "Dashboard": {
    "Date": "/Date(1326063600000+0000)/"
    }
}

What is the approach of converting such formatted date using SBJSON? I extracted the value to NSString using

//dict is NSDictionary with Dashboard
NSString* dateString=[dict objectForKey:@"Date"];

and then stopped. Any suggestions wil be appreciated.


Solution

  • From the comments, it already sounds like you've extracted the timestamp.

    You probably want to use NSDate epoch constructor: dateWithTimeIntervalSince1970:

    NSDate *date = [NSDate dateWithTimeIntervalSince1970:SOME_TIME_INTERVAL];
    

    In this case, SOME_TIME_INTERVAL would be the NSTimeInterval (just an alias for double) value: 1326063600. Don't forget to divide the value you get by 1000. NSTimeIntervals are in seconds, not milliseconds.