invalid type in json write (__nsdate)

/* Generate JSON data from a Foundation object. If the object will not produce valid JSON then an exception will be thrown. Setting the NSJSONWritingPrettyPrinted option will generate JSON with whitespace designed to make the output more readable. If that option is not set, the most compact possible JSON will be generated. If an error occurs, the error parameter will be set and the return value will be nil. The resulting data is a encoded in UTF-8.
*/
// NSData *jsonData = [NSJSONSerialization dataWithJSONObject:accoutInfoDict options:0 error:nil];

invalid type in json write (__nsdate)
NSDate --> expirationDate = "2017-06-04 19:00:00 +0000";
{
expirationDate = "2017-06-04 19:00:00 +0000";
largeAvatar = "https://tva3.sinaaa8.jpg";
midAvatar = "xxx";
openId = xxx;
sex = xxx;
sgid = "xxx";
tinyAvatar = "xxx";
token = "xxx";
uniqName = xxx;
userId = "xxx";
}

解决方案 使用NSKeyedArchiver 压缩dict 得到nsdata
NSData * jsonData = [NSKeyedArchiver archivedDataWithRootObject:accoutInfoDict];
/*
An NSData object containing the encoded form of the object graph whose root object is rootObject. The format of the archive is NSPropertyListBinaryFormat_v1_0.
*/
解析data 时需要用NSKeyedUnarchiver 反序列化 解析data 得到dict
NSDictionary *dictAccount = [NSKeyedUnarchiver unarchiveObjectWithData:accountData];

你可能感兴趣的:(invalid type in json write (__nsdate))