CocoaJSON

This code has been made redundant by: TouchJSON

Blake Seely released some code yesterday to convert Cocoa datatypes to JSON. I’ve had similar code that I’ve been meaning to put online for a while now. So now the world has gone from zero to two Cocoa code-bases to read/write JSON.

The code is in subversion here, and an archived version can be downloaded here: CocoaJSON.zip. The code is standalone and some unit tests are provided.

This entry was posted in Default. Bookmark the permalink.
  • ThomasW
    When I click the 'some code' link I get "Repository access denied."
  • This code has been made redundant by:

    http://code.google.com/p/touchcode/wiki/TouchJSON
  • See /subversion-moved/
  • rob
    Neither the link to the zip or the link work anymore. Is this still available?
  • Ian
    Under what license are you publishing this? I see no mention of a license in any of your files.

    Thanks!
  • Hey Mr Mojo,

    It _should_ work, so you could be doing something braindead. Or it could just be buggy. I'm not doing any work on CocoaJSON right now so feel free to fix it and send me a patch :-)

    Otherwise I'll add to the list of things I need to do. I really need a public facing bug tracker.

    Cheers.

    Jon.
  • Jim
    Maybe I'm being incredibly stupid, but these classes seem to choke on whitespace. The code isn't capable of parsing something simple like:

    {
    "firstName": "Jim",
    "lastName": "Morrison"
    }

    I thought the culprit might be NSScanner_Extensions skipWhitespace. Surely this should be using whitespaceAndNewlineCharacterSet instead of whitespaceCharacterSet?

    So, I tried changing it. This got the scanner a couple of characters further but it still bails out at the first opportunity. I had a look at the unit tests to see whether they would prove my suspicions wrong. They only served to confirm them, though: all unit tests test against single-line input.

    Am I expecting too much? Am I missing something?
  • Well feel free to create your own multiple array object in Objective-C then just provide a serialiser/deserialiser methods for them. Not sure if I made my code extensible in this way - but should be easy to add in.
  • David
    Yes.. I know JSON handles it fine.. but making multidimensional arrays in Cocoa using NSArray's is very convoluted when looking at the code to create one... Perhaps I'm being too picky :)
  • Not sure what you mean about JSON not handling multidimensional arrays? Did a few quick tests, and both the CocoaJSON code, and my own code outputs it just fine - but maybe you're question isn't whether it can handle multidimensional arrays, but whether it's easy?
  • David
    I've been looking at using JSON as well but it appears some data just isn't represented well with Cocoa data structures such as multidimensional arrays.. I'm using QuickLite to get an NSArray of values for each dimension and then simply enumerating through the array to get each integer value and outputting it to a space delimited text file which is uploaded to the server. Javascript on the server then reads the values from the text file to create the multidimensional array.. There has to be a cleaner way then what I am doing.
  • You can never have too much code :) I have to credit Buzz for the idea, though - and he mentioned that he got some code started, too. Can't wait to check yours out - I'm definitely curious to see how others are handling a few things I had questions about!
blog comments powered by Disqus