LCJSONResponseSerializer
Objective-C
@interface LCJSONResponseSerializer : LCHTTPResponseSerializer
Swift
class LCJSONResponseSerializer : LCHTTPResponseSerializer
LCJSONResponseSerializer
is a subclass of LCHTTPResponseSerializer
that validates and decodes JSON responses.
By default, LCJSONResponseSerializer
accepts the following MIME types, which includes the official standard, application/json
, as well as other commonly-used types:
application/json
text/json
text/javascript
In RFC 7159 - Section 8.1, it states that JSON text is required to be encoded in UTF-8, UTF-16, or UTF-32, and the default encoding is UTF-8. NSJSONSerialization provides support for all the encodings listed in the specification, and recommends UTF-8 for efficiency. Using an unsupported encoding will result in serialization error. See the NSJSONSerialization
documentation for more details.
-
Undocumented
Declaration
Objective-C
- (instancetype)init;
Swift
init()
-
Options for reading the response JSON data and creating the Foundation objects. For possible values, see the
NSJSONSerialization
documentation section “NSJSONReadingOptions”.0
by default.Declaration
Objective-C
@property (nonatomic) NSJSONReadingOptions readingOptions;
Swift
var readingOptions: JSONSerialization.ReadingOptions { get set }
-
Whether to remove keys with
NSNull
values from response JSON. Defaults toNO
.Declaration
Objective-C
@property (nonatomic) BOOL removesKeysWithNullValues;
Swift
var removesKeysWithNullValues: Bool { get set }
-
Creates and returns a JSON serializer with specified reading and writing options.
Declaration
Objective-C
+ (nonnull instancetype)serializerWithReadingOptions: (NSJSONReadingOptions)readingOptions;
Swift
convenience init(readingOptions: JSONSerialization.ReadingOptions = [])
Parameters
readingOptions
The specified JSON reading options.