Statistics
| Branch: | Revision:

root / json-framework-3.2.0 / Classes / SBJsonWriter.h @ 3ebe9884

History | View | Annotate | Download (4.2 kB)

1
/*
2
 Copyright (C) 2009 Stig Brautaset. All rights reserved.
3

4
 Redistribution and use in source and binary forms, with or without
5
 modification, are permitted provided that the following conditions are met:
6

7
 * Redistributions of source code must retain the above copyright notice, this
8
   list of conditions and the following disclaimer.
9

10
 * Redistributions in binary form must reproduce the above copyright notice,
11
   this list of conditions and the following disclaimer in the documentation
12
   and/or other materials provided with the distribution.
13

14
 * Neither the name of the author nor the names of its contributors may be used
15
   to endorse or promote products derived from this software without specific
16
   prior written permission.
17

18
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
22
 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 */
29

    
30
#import <Foundation/Foundation.h>
31

    
32
/**
33
 The JSON writer class.
34

35
 This uses SBJsonStreamWriter internally.
36

37
 */
38

    
39
@interface SBJsonWriter : NSObject
40

    
41
/**
42
 The maximum recursing depth.
43

44
 Defaults to 32. If the input is nested deeper than this the input will be deemed to be
45
 malicious and the parser returns nil, signalling an error. ("Nested too deep".) You can
46
 turn off this security feature by setting the maxDepth value to 0.
47
 */
48
@property NSUInteger maxDepth;
49

    
50
/**
51
 Return an error trace, or nil if there was no errors.
52

53
 Note that this method returns the trace of the last method that failed.
54
 You need to check the return value of the call you're making to figure out
55
 if the call actually failed, before you know call this method.
56
 */
57
@property (readonly, copy) NSString *error;
58

    
59
/**
60
 Whether we are generating human-readable (multiline) JSON.
61

62
 Set whether or not to generate human-readable JSON. The default is NO, which produces
63
 JSON without any whitespace. (Except inside strings.) If set to YES, generates human-readable
64
 JSON with linebreaks after each array value and dictionary key/value pair, indented two
65
 spaces per nesting level.
66
 */
67
@property BOOL humanReadable;
68

    
69
/**
70
 Whether or not to sort the dictionary keys in the output.
71

72
 If this is set to YES, the dictionary keys in the JSON output will be in sorted order.
73
 (This is useful if you need to compare two structures, for example.) The default is NO.
74
 */
75
@property BOOL sortKeys;
76

    
77
/**
78
 An optional comparator to be used if sortKeys is YES.
79

80
 If this is nil, sorting will be done via @selector(compare:).
81
 */
82
@property (copy) NSComparator sortKeysComparator;
83

    
84
/**
85
 Return JSON representation for the given object.
86

87
 Returns a string containing JSON representation of the passed in value, or nil on error.
88
 If nil is returned and error is not NULL, *error can be interrogated to find the cause of the error.
89

90
 @param value any instance that can be represented as JSON text.
91
 */
92
- (NSString*)stringWithObject:(id)value;
93

    
94
/**
95
 Return JSON representation for the given object.
96

97
 Returns an NSData object containing JSON represented as UTF8 text, or nil on error.
98

99
 @param value any instance that can be represented as JSON text.
100
 */
101
- (NSData*)dataWithObject:(id)value;
102

    
103
/**
104
 Return JSON representation (or fragment) for the given object.
105

106
 Returns a string containing JSON representation of the passed in value, or nil on error.
107
 If nil is returned and error is not NULL, *error can be interrogated to find the cause of the error.
108

109
 @param value any instance that can be represented as a JSON fragment
110
 @param error pointer to object to be populated with NSError on failure
111

112
  @warning Deprecated in Version 3.2; will be removed in 4.0
113

114
 */
115
- (NSString*)stringWithObject:(id)value
116
                        error:(NSError**)error __attribute__ ((deprecated));
117

    
118

    
119
@end