-1
JSONファイルの解析方法に問題があります。私はSwiftのために新しく、JSOを解析しようとしましたが空になりました。スウィフトでJSONを解析する3
問題は、私はJSON
JSONを解析する方法である:
{
"list" : {
"meta" : {
"type" : "resource-list",
"start" : 0,
"count" : 188
},
"resources" : [
{
"resource" : {
"classname" : "Quote",
"fields" : {
"name" : "USD/KRW",
"price" : "1147.310059",
"symbol" : "KRW=X",
"ts" : "1489185046",
"type" : "currency",
"utctime" : "2017-03-10T22:30:46+0000",
"volume" : "0"
}
}
}
,
{
"resource" : {
"classname" : "Quote",
"fields" : {
"name" : "SILVER 1 OZ 999 NY",
"price" : "0.058634",
"symbol" : "XAG=X",
"ts" : "1489325701",
"type" : "currency",
"utctime" : "2017-03-12T13:35:01+0000",
"volume" : "36"
}
}
}
スウィフトコード:
let Url = NSURL(string: stockUrl)
let request = NSMutableURLRequest(url: Url! as URL)
let task = URLSession.shared.dataTask(with: request as URLRequest){ data, response, error in
if error != nil
{
print("error=\(error)")
return
}
do {
if let data = try JSONSerialization.jsonObject(with: data!, options: []) as? [String: AnyObject]{
let list = data["list"] as? [[String: Any]] ?? []
print(list)
}
} catch let error as NSError {
print(error.localizedDescription)
}
}
task.resume()
}
lsabekovあなたのコードを表示しますか? –
[Swift 3 json parsing]の複製の可能性があります(http://stackoverflow.com/questions/39609726/swift-3-json-parsing) – Priyal