SBJsonWriter Class Reference
Inherits from | NSObject |
Declared in | SBJsonWriter.h |
Tasks
-
maxDepth
The maximum recursing depth.
property -
error
Return an error trace, or nil if there was no errors.
property -
humanReadable
Whether we are generating human-readable (multiline) JSON.
property -
sortKeys
Whether or not to sort the dictionary keys in the output.
property -
sortKeysComparator
An optional comparator to be used if sortKeys is YES.
property -
– stringWithObject:
Return JSON representation for the given object.
-
– dataWithObject:
Return JSON representation for the given object.
-
– stringWithObject:error:
Return JSON representation (or fragment) for the given object.
Properties
error
Return an error trace, or nil if there was no errors.
@property (readonly, copy) NSString *error
Discussion
Note that this method returns the trace of the last method that failed. You need to check the return value of the call you’re making to figure out if the call actually failed, before you know call this method.
Declared In
SBJsonWriter.h
humanReadable
Whether we are generating human-readable (multiline) JSON.
@property BOOL humanReadable
Discussion
Set whether or not to generate human-readable JSON. The default is NO, which produces JSON without any whitespace. (Except inside strings.) If set to YES, generates human-readable JSON with linebreaks after each array value and dictionary key/value pair, indented two spaces per nesting level.
Declared In
SBJsonWriter.h
maxDepth
The maximum recursing depth.
@property NSUInteger maxDepth
Discussion
Defaults to 32. If the input is nested deeper than this the input will be deemed to be malicious and the parser returns nil, signalling an error. (“Nested too deep”.) You can turn off this security feature by setting the maxDepth value to 0.
Declared In
SBJsonWriter.h
sortKeys
Whether or not to sort the dictionary keys in the output.
@property BOOL sortKeys
Discussion
If this is set to YES, the dictionary keys in the JSON output will be in sorted order. (This is useful if you need to compare two structures, for example.) The default is NO.
Declared In
SBJsonWriter.h
sortKeysComparator
An optional comparator to be used if sortKeys is YES.
@property (copy) NSComparator sortKeysComparator
Discussion
If this is nil, sorting will be done via @selector(compare:).
Declared In
SBJsonWriter.h
Instance Methods
dataWithObject:
Return JSON representation for the given object.
- (NSData *)dataWithObject:(id)value
Parameters
- value
-
any instance that can be represented as JSON text.
Discussion
Returns an NSData object containing JSON represented as UTF8 text, or nil on error.
Declared In
SBJsonWriter.h
stringWithObject:
Return JSON representation for the given object.
- (NSString *)stringWithObject:(id)value
Parameters
- value
-
any instance that can be represented as JSON text.
Discussion
Returns a string containing JSON representation of the passed in value, or nil on error. If nil is returned and error is not NULL, *error can be interrogated to find the cause of the error.
Declared In
SBJsonWriter.h
stringWithObject:error:
Return JSON representation (or fragment) for the given object.
- (NSString *)stringWithObject:(id)value error:(NSError **)error
Parameters
- value
-
any instance that can be represented as a JSON fragment
- error
-
pointer to object to be populated with NSError on failure
Discussion
Returns a string containing JSON representation of the passed in value, or nil on error. If nil is returned and error is not NULL, *error can be interrogated to find the cause of the error.
Warning: Deprecated in Version 3.2; will be removed in 4.0
Declared In
SBJsonWriter.h