views:

22

answers:

1

Hello,

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 needs to go into the category to make this work?

A: 

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

heckj
is it possible to leave the coredata attribute as NSDate, but the json as string, i am using code to loop through the NSManagedObject and pull the attributes, how would i add in this exception for the date as a string
iAm
of course it is, but this was a dumb question, sorry for askin, i needed to do this one on my own.
iAm
heckj -- thank you, your response gave me the insight that I needed to finish.
iAm
you're very welcome! I've run into the same kind of thing myself, just slightly backwards. Was doing date string parsing and stuffing results into a SQLite database on the iPhone, and then later making comparisons. Never quite hit the JSON transformation, but same effective issue.
heckj