SBJsonParser.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 Parse JSON Strings and NSData objects
  27. This uses SBJsonStreamParser internally.
  28. @see @ref objc2json
  29. */
  30. @interface SBJsonParser : NSObject
  31. /**
  32. @brief The maximum recursing depth.
  33. Defaults to 32. If the input is nested deeper than this the input will be deemed to be
  34. malicious and the parser returns nil, signalling an error. ("Nested too deep".) You can
  35. turn off this security feature by setting the maxDepth value to 0.
  36. */
  37. @property NSUInteger maxDepth;
  38. /**
  39. @brief Description of parse error
  40. This method returns the trace of the last method that failed.
  41. You need to check the return value of the call you're making to figure out
  42. if the call actually failed, before you know call this method.
  43. @return A string describing the error encountered, or nil if no error occured.
  44. */
  45. @property(copy) NSString *error;
  46. /**
  47. @brief Return the object represented by the given NSData object.
  48. The data *must* be UTF8 encoded.
  49. @param data An NSData containing UTF8 encoded data to parse.
  50. @return The NSArray or NSDictionary represented by the object, or nil if an error occured.
  51. */
  52. - (id)objectWithData:(NSData*)data;
  53. /**
  54. @brief Return the object represented by the given string
  55. This method converts its input to an NSData object containing UTF8 and calls -objectWithData: with it.
  56. @return The NSArray or NSDictionary represented by the object, or nil if an error occured.
  57. */
  58. - (id)objectWithString:(NSString *)repr;
  59. /**
  60. @brief Return the object represented by the given string
  61. This method calls objectWithString: internally. If an error occurs, and if @p error
  62. is not nil, it creates an NSError object and returns this through its second argument.
  63. @param jsonText the json string to parse
  64. @param error pointer to an NSError object to populate on error
  65. @return The NSArray or NSDictionary represented by the object, or nil if an error occured.
  66. */
  67. - (id)objectWithString:(NSString*)jsonText
  68. error:(NSError**)error;
  69. @end