-1
私は迅速かつ客観的なことを学んでいます。私はすべてのショーのJsonで "show_name"を抽出したいと思います。私は素早くxcodeでjsonオブジェクトをループできません
これは私のJSONです:
{
"data": {
"12 Monkeys": {
"air_by_date": 0,
"anime": 0,
"cache": {
"banner": 1,
"poster": 1
},
"indexerid": 272644,
"language": "en",
"network": "Syfy",
"next_ep_airdate": "",
"paused": 0,
"quality": "SD",
"show_name": "12 Monkeys",
"sports": 0,
"status": "Continuing",
"subtitles": 1,
"tvdbid": 272644
},
"2 Broke Girls": {
"air_by_date": 0,
"anime": 0,
"cache": {
"banner": 1,
"poster": 1
},
"indexerid": 248741,
"language": "en",
"network": "CBS",
"next_ep_airdate": "2016-10-10",
"paused": 0,
"quality": "SD",
"show_name": "2 Broke Girls",
"sports": 0,
"status": "Continuing",
"subtitles": 0,
"tvdbid": 248741
},
"American Horror Story": {
"air_by_date": 0,
"anime": 0,
"cache": {
"banner": 1,
"poster": 1
},
"indexerid": 250487,
"language": "en",
"network": "FX (US)",
"next_ep_airdate": "2016-09-14",
"paused": 0,
"quality": "SD",
"show_name": "American Horror Story",
"sports": 0,
"status": "Continuing",
"subtitles": 0,
"tvdbid": 250487
},
は、これは私のコードであると私はswiftyJsonを使用します。
class ViewController: UIViewController {
let baseURL = "http://xxx.xxx.xxx.xxx:8083/api/api/?cmd=shows&sort=name&paused=0"
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
getJSON()
}
func getJSON(){
let url = NSURL(string: baseURL)
let request = NSURLRequest(URL: url!)
let session = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration())
let task = session.dataTaskWithRequest(request)
{ (data, response, error) -> Void in
if error == nil {
let swiftyJSON = JSON(data: data!)
print(swiftyJSON)
let title = swiftyJSON["data"]["Sense8"]["show_name"]
print(title)
}else {
print("there was an error")
}
}
task.resume()
}
}