NSInvalidArgumentException, reason: 'Invalid type in JSON write (__NSDate)'

前端 未结 8 2169
南旧
南旧 2021-02-04 01:05

I\'m getting this exception when I try to JSON encode NSDate object.I believe NSDate is not compatible for JSON encoding. but I must encode the date.Any solutions?



        
8条回答
  •  野的像风
    2021-02-04 01:21

    The simplest way to store and retrieve a NSDate object in JSON would be to use the timeIntervalSince1970 property of NSDate.

    The returned NSTimeInterval (double) is pretty standard and can easily be converted back to a NSDate object using:

    NSDate dateWithTimeIntervalSince1970:<#(NSTimeInterval)#>
    

提交回复
热议问题