开发者

How to add NSDate+BSJSONAdditions to the BSJSON project

开发者 https://www.devze.com 2023-01-08 06:13 出处:网络
I need to know how to get BSJSON to handle the NSDate that is in coredata in the json it returns null for the date, what n开发者_Go百科eeds to go into the category to make this work?Assuming you\'re t

I need to know how to get BSJSON to handle the NSDate that is in coredata in the json it returns null for the date, what n开发者_Go百科eeds to go into the category to make this work?


Assuming you're talking about http://github.com/blakeseely/bsjsonadditions, there's really no easy way to get a JSON object and dump it into NSDate. You need some intervening logic - like asserting a common date format, and then do the NSDate <-> String conversion yourself, and letting the JSON format represent the string.

Common methods for doing this are to use "# of seconds since Epoch" to represent the time, or to just fully qualify out an ISO-8601 time string. Which is easier often depends on what other systems you're working with and which they can easily convert and use. The first is accomplished super-easy with Objective-C by using NSDate dateWithTimeIntervalSince1970:

Going in and out of an ISO-8601 string is a bit more work, and you'll head into the realm of NSDateFormatter

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号