Reputation: 11
I use dataTaskWithRequest and get json of array with two objects in it (these objects are key,value) and I want check one value of key in two objects.
this is my code :
let task = session.dataTaskWithRequest(request, completionHandler: {data, response, error -> Void in
print("Response: \(response)")
var jsonArray: [String:AnyObject]!
do {
jsonArray = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions()) as? [String:AnyObject]
} catch {
print(error)
}
for json in jsonArray {
print("object json reciver :",json)
//type (string , anyobject) has no subscript member
print("state :",json["state"])
}
})
Upvotes: 1
Views: 5081
Reputation: 18181
json
is a variable typed (String, AnyObject)
. You cannot subscript tuples.
Replace the following:
print("state :",json["state"])
with:
print("\(json.0) : \(json.1)")
Upvotes: 6