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.
  • http://www.blakeseely.com Blake Seely

    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!

  • http://www.blakeseely.com Blake Seely

    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!

  • 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.

  • 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.

  • http://www.blakeseely.com Blake Seely

    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?

  • http://www.blakeseely.com Blake Seely

    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

    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 :)

  • 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 :)

  • http://toxicsoftware.com Jonathan Wight

    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.

  • http://toxicsoftware.com Jonathan Wight

    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.

  • http://www.thedoors.com 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?

  • http://www.thedoors.com 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:<br><br>{<br> "firstName": "Jim",<br> "lastName": "Morrison"<br>}<br><br>I thought the culprit might be NSScanner_Extensions skipWhitespace. Surely this should be using whitespaceAndNewlineCharacterSet instead of whitespaceCharacterSet?<br><br>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.<br><br>Am I expecting too much? Am I missing something?

  • http://toxicsoftware.com/ schwa

    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.

  • http://toxicsoftware.com/ schwa

    Hey Mr Mojo,<br><br>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 :-)<br><br>Otherwise I'll add to the list of things I need to do. I really need a public facing bug tracker.<br><br>Cheers.<br><br> Jon.

  • Ian

    Under what license are you publishing this? I see no mention of a license in any of your files.

    Thanks!

  • Ian

    Under what license are you publishing this? I see no mention of a license in any of your files.<br><br>Thanks!

  • http://robrohan.com rob

    Neither the link to the zip or the link work anymore. Is this still available?

  • http://robrohan.com rob

    Neither the link to the zip or the link work anymore. Is this still available?

  • http://toxicsoftware.com/ schwa

    See /subversion-moved/

  • http://toxicsoftware.com/ schwa

    See /subversion-moved/

  • Pingback: From Concentrate Software

  • Pingback: napyfab:blog» Blog Archive » links for 2007-10-16

  • http://google.com/ ranjeet

    This is good apis

  • ThomasW

    When I click the 'some code' link I get “Repository access denied.”

  • http://toxicsoftware.com schwa

    This code has been made redundant by:

    http://code.google.com/p/touchcode/wiki/TouchJSON

  • http://toxicsoftware.com schwa

    This code has been made redundant by:

    http://code.google.com/p/touchcode/wiki/TouchJSON