Я публикую свой результат работы в качестве ответа, надеюсь, он поможет другим в будущем
Для сериализации NSDictionary
от результата API до NSString
- (NSString *)NSStringFromNSDictionary:(NSDictionary *)dict
{
long Timestamp = [[dict objectForKey:@"Timestamp"] longValue];
long Machine = [[dict objectForKey:@"Machine"] longValue];
long Pid = [[dict objectForKey:@"Pid"] longValue];
long Increment = [[dict objectForKey:@"Increment"] longValue];
NSString *oid = [NSString stringWithFormat:@"%08lx%06lx%04lx%06lx", Timestamp, Machine, Pid, Increment];
return oid;
}
Для сериализации NSString
обратно в .Net Mongo ObjectId в виде NSDictionary
- (NSDictionary *)NSStringFromNSDictionary:(NSString *)oid
{
long Timestamp = strtol([[oid substringToIndex:8] UTF8String], NULL, 16);
long Machine = strtol([[oid substringWithRange:NSMakeRange(8,6)] UTF8String], NULL, 16);
long Pid = strtol([[oid substringWithRange:NSMakeRange(14,4)] UTF8String], NULL, 16);
long Increment = strtol([[oid substringFromIndex:18] UTF8String], NULL, 16);
NSDictionary * dict = @{@"Timestamp": [NSNumber numberWithLong:Timestamp]
,@"Machine": [NSNumber numberWithLong:Machine]
,@"Pid": [NSNumber numberWithLong:Pid]
,@"Increment": [NSNumber numberWithLong:Increment]
,@"CreationTime": [NSString stringWithFormat:@"/Date(%ld)/",Timestamp*1000]
};
return dict;
}