DBJsonParser.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. #import "DBJsonBase.h"
  26. /**
  27. @brief Options for the parser class.
  28. This exists so the DBJSON facade can implement the options in the parser without having to re-declare them.
  29. */
  30. @protocol DBJsonParser
  31. /**
  32. @brief Return the object represented by the given string.
  33. Returns the object represented by the passed-in string or nil on error. The returned object can be
  34. a string, number, boolean, null, array or dictionary.
  35. @param repr the json string to parse
  36. */
  37. - (id)objectWithString:(NSString *)repr;
  38. @end
  39. /**
  40. @brief The JSON parser class.
  41. JSON is mapped to Objective-C types in the following way:
  42. @li Null -> NSNull
  43. @li String -> NSMutableString
  44. @li Array -> NSMutableArray
  45. @li Object -> NSMutableDictionary
  46. @li Boolean -> NSNumber (initialised with -initWithBool:)
  47. @li Number -> NSDecimalNumber
  48. Since Objective-C doesn't have a dedicated class for boolean values, these turns into NSNumber
  49. instances. These are initialised with the -initWithBool: method, and
  50. round-trip back to JSON properly. (They won't silently suddenly become 0 or 1; they'll be
  51. represented as 'true' and 'false' again.)
  52. JSON numbers turn into NSDecimalNumber instances,
  53. as we can thus avoid any loss of precision. (JSON allows ridiculously large numbers.)
  54. */
  55. @interface DBJsonParser : DBJsonBase <DBJsonParser> {
  56. @private
  57. const char *c;
  58. }
  59. @end
  60. // don't use - exists for backwards compatibility with 2.1.x only. Will be removed in 2.3.
  61. @interface DBJsonParser (Private)
  62. - (id)fragmentWithString:(id)repr;
  63. @end