SBJson  3.0.4
Public Member Functions | Properties
SBJsonWriter Class Reference

The JSON writer class. More...

Inherits NSObject.

List of all members.

Public Member Functions

(NSString *)  - stringWithObject:
  Return JSON representation for the given object.
(NSData *)  - dataWithObject:
  Return JSON representation for the given object.
(NSString *)  - stringWithObject:error:
  Return JSON representation (or fragment) for the given object.

Properties

NSUInteger  maxDepth
  The maximum recursing depth.
NSString *  error
  Return an error trace, or nil if there was no errors.
BOOL  humanReadable
  Whether we are generating human-readable (multiline) JSON.
BOOL  sortKeys
  Whether or not to sort the dictionary keys in the output.

Detailed Description

This uses SBJsonStreamWriter internally.

See also:
JSON to Objective-C

Member Function Documentation

- (NSData *) dataWithObject: (id)  value

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

Parameters:
value any instance that can be represented as JSON text.
- (NSString *) stringWithObject: (id)  value

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.

Parameters:
value any instance that can be represented as JSON text.
- (NSString *) stringWithObject: (id)  value
error: (NSError**)  error 

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.

Parameters:
value any instance that can be represented as a JSON fragment
error pointer to object to be populated with NSError on failure

Property Documentation

- (NSString *) error [read, copy]

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.

- (BOOL) humanReadable [read, write, assign]

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.

- (NSUInteger) maxDepth [read, write, assign]

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.

- (BOOL) sortKeys [read, write, assign]

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.


The documentation for this class was generated from the following files: