The FMPUtils.Parser class is used to parse JSON structures obtained during the work with framework.
class Parser
Method | Description |
getStatus() | Get status from the "status" field of JSON structure. func getStatus() -> FMPStatus? |
getErrors() | Get list of errors from the "errors" field of JSON structure. func getErrors() -> [FMPError]? |
Get status:
let json: NSDictionary = ["status" : "ok"]
// Build an instance of the FMPUtils.Parser class. For details see examples for FMPUtils.Parser.Builder.
let parser: FMPUtils.Parser = FMPUtils().parser
.json(json)
.build()
// Get status
let status: FMPStatus? = parser.getStatus() // FMPStatus.ok
Get list of errors:
let json: NSDictionary = ["status" : "error", "errors": [["code": 503, "descriptions": ["Service Unavailable"]]]]
// Build an instance of the FMPUtils.Parser class. For details see examples for FMPUtils.Parser.Builder.
let parser: FMPUtils.Parser = FMPUtils().parser
.json(json)
.build()
// Get list of errors
let errors: [FMPError]? = parser.getErrors() // [FMPError.error(code: "503", description: "Service Unavailable")]
See also: