SFJsonUtils Class Reference
Inherits from | NSObject |
---|---|
Declared in | SFJsonUtils.h |
+ lastError
The last error that was logged during a JSON conversion operation.
+ (NSError *)lastError
Return Value
The last error that was logged during a JSON conversion operation.
Declared In
SFJsonUtils.h
+ JSONRepresentation:
Creates the JSON representation of an object.
+ (NSString *)JSONRepresentation:(id)object
Parameters
object |
The object to JSON-ify |
---|
Return Value
a JSON string representation of an Objective-C object
Declared In
SFJsonUtils.h
+ JSONRepresentation:options:
Creates the JSON representation of an object.
+ (nullable NSString *)JSONRepresentation:(id)object options:(NSJSONWritingOptions)options
Parameters
object |
The object to JSON-ify |
---|---|
options |
for json-ization |
Return Value
a JSON string representation of an Objective-C object
Declared In
SFJsonUtils.h
+ JSONDataRepresentation:
Creates the JSON-as-NSData representation of an object.
+ (NSData *)JSONDataRepresentation:(id)obj
Parameters
obj |
The object to JSON-ify. |
---|
Return Value
A JSON string in NSData format, UTF8 encoded.
Declared In
SFJsonUtils.h
+ JSONDataRepresentation:options:
Creates the JSON-as-NSData representation of an object.
+ (nullable NSData *)JSONDataRepresentation:(id)obj options:(NSJSONWritingOptions)options
Parameters
obj |
The object to JSON-ify. |
---|---|
options |
for json-ization |
Return Value
A JSON string in NSData format, UTF8 encoded.
Declared In
SFJsonUtils.h
+ objectFromJSONString:
Creates an object from a string of JSON data.
+ (nullable id)objectFromJSONString:(NSString *)jsonString
Parameters
jsonString |
A JSON object string. |
---|
Return Value
An Objective-C object such as an NSDictionary or NSArray.
Declared In
SFJsonUtils.h
+ objectFromJSONData:
Creates an object from a JSON-as-NSData object.
+ (id)objectFromJSONData:(NSData *)jsonData
Parameters
jsonData |
JSON data in an NSData wrapper (UTF8 encoding assumed). |
---|
Return Value
An Objective-C object such as an NSDictionary or NSArray.
Declared In
SFJsonUtils.h
+ projectIntoJson:path:
Pull a value from the json-derived object by path (“.” delimited).
+ (id)projectIntoJson:(NSDictionary *)jsonObj path:(NSString *)path
Parameters
jsonObj |
The JSON object that contains the requested JSON path. |
---|---|
path |
Requested JSON path. |
Discussion
Examples (in pseudo code):
json = {“a”: {“b”: [{“c”:“xx”}, {“c”:“xy”}, {“d”: [{“e”:1}, {“e”:2}]}, {“d”: [{“e”:3}, {“e”:4}]}] }} projectIntoJson(jsonObj, “a”) = {“b”: [{“c”:“xx”}, {“c”:“xy”}, {“d”: [{“e”:1}, {“e”:2}]}, {“d”: [{“e”:3}, {“e”:4}]} ]} projectIntoJson(json, “a.b”) = [{c:“xx”}, {c:“xy”}, {“d”: [{“e”:1}, {“e”:2}]}, {“d”: [{“e”:3}, {“e”:4}]}] projectIntoJson(json, “a.b.c”) = [“xx”, “xy”] // new in 4.1 projectIntoJson(json, “a.b.d”) = [[{“e”:1}, {“e”:2}], [{“e”:3}, {“e”:4}]] // new in 4.1 projectIntoJson(json, “a.b.d.e”) = [[1, 2], [3, 4]] // new in 4.1
Declared In
SFJsonUtils.h