NSInvalidArgumentException,原因:'JSON写入中的无效类型(__NSDate)' [英] NSInvalidArgumentException, reason: 'Invalid type in JSON write (__NSDate)'

查看:3400
本文介绍了NSInvalidArgumentException,原因:'JSON写入中的无效类型(__NSDate)'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试JSON编码NSDate对象时,我收到此异常。我相信NSDate与JSON编码不兼容。但我必须编码date.Any解决方案?

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?

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (__NSDate)'


推荐答案

第一个商店NSString中的数据。然后将您的字符串转换为NSDate。

FIrst store your data in NSString. And then convert your string to NSDate.

您可以参考SO:

将NSString转换为NSDate(并再次返回)

NSString转换为NSDate转换问题

如何使用NSDateFormatter将NSString转换为NSDate?

这篇关于NSInvalidArgumentException,原因:'JSON写入中的无效类型(__NSDate)'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆