问题
Im want to check the current subscription status of an Auto Renew In App purchase. Im getting the receipt data via JSON, im after some advice on how to use/query the returned data
if let parseJSON = json {
println("Recipt \(parseJSON)")
}
Returns
Recipt {
environment = Sandbox;
status = 21004;
}
Whilst I know this wouldn't compile, I want to to do is something along the lines of an if statement like:
if parseJSON contains status = 21004 {
//Do something
}
回答1:
You might consider something like
if parseJSON["status"] as? Int == 21004 {
// do something
}
This works because as? Int will automatically convert a NSNumber to a Swift integer, and because there is a version of == that accepts optional arguments.
public func ==<T : Equatable>(lhs: T?, rhs: T?) -> Bool
回答2:
You can use SwiftyJSON. It will be:
let parseJSON = JSON(data: json)
if parseJSON["status"] == "21004" {
//do something
}
If it not working, try to write parseJSON["status"].stringValue
来源:https://stackoverflow.com/questions/32039421/using-returned-json-status-in-an-if-statement-checking-iap-auto-renew-receipt