NSObject+DBJSON.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. Copyright (C) 2009 Stig Brautaset. All rights reserved.
  3. Redistribution and use in source and binary forms, with or without
  4. modification, are permitted provided that the following conditions are met:
  5. * Redistributions of source code must retain the above copyright notice, this
  6. list of conditions and the following disclaimer.
  7. * Redistributions in binary form must reproduce the above copyright notice,
  8. this list of conditions and the following disclaimer in the documentation
  9. and/or other materials provided with the distribution.
  10. * Neither the name of the author nor the names of its contributors may be used
  11. to endorse or promote products derived from this software without specific
  12. prior written permission.
  13. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  14. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  16. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  17. FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  18. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  19. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  20. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  21. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  22. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. #import <Foundation/Foundation.h>
  25. /**
  26. @brief Adds JSON generation to Foundation classes
  27. This is a category on NSObject that adds methods for returning JSON representations
  28. of standard objects to the objects themselves. This means you can call the
  29. -JSONRepresentation method on an NSArray object and it'll do what you want.
  30. */
  31. @interface NSObject (NSObject_DBJSON)
  32. /**
  33. @brief Returns a string containing the receiver encoded as a JSON fragment.
  34. This method is added as a category on NSObject but is only actually
  35. supported for the following objects:
  36. @li NSDictionary
  37. @li NSArray
  38. @li NSString
  39. @li NSNumber (also used for booleans)
  40. @li NSNull
  41. @deprecated Given we bill ourselves as a "strict" JSON library, this method should be removed.
  42. */
  43. - (NSString *)JSONFragment;
  44. /**
  45. @brief Returns a string containing the receiver encoded in JSON.
  46. This method is added as a category on NSObject but is only actually
  47. supported for the following objects:
  48. @li NSDictionary
  49. @li NSArray
  50. */
  51. - (NSString *)JSONRepresentation;
  52. @end