Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 用JSON数据填充UILabel并编码URL_Ios_Json_Swift - Fatal编程技术网

Ios 用JSON数据填充UILabel并编码URL

Ios 用JSON数据填充UILabel并编码URL,ios,json,swift,Ios,Json,Swift,首先,我需要用前面的varpasand值对JSON url进行编码,然后我需要获取JSON数据并填充一些UILabel。这是我的密码。我正在使用Alamofire和SwiftyJSON var pasarid = "" var arrRes = [[String:AnyObject]]() @IBOutlet weak var completo: UILabel! @IBOutlet weak var historia: UILabel! @IBOutlet weak var año: UI

首先,我需要用前面的var
pasand
值对JSON url进行编码,然后我需要获取JSON数据并填充一些UILabel。这是我的密码。我正在使用Alamofire和SwiftyJSON

var pasarid = ""
var arrRes = [[String:AnyObject]]()


@IBOutlet weak var completo: UILabel!
@IBOutlet weak var historia: UILabel!
@IBOutlet weak var año: UILabel!
@IBOutlet weak var estilo: UILabel!
@IBOutlet weak var direccion: UILabel!
@IBOutlet weak var director: UILabel!
@IBOutlet weak var titulares: UILabel!



override func viewDidLoad() {
    super.viewDidLoad()

    Alamofire.request(.GET, "http://elpenitente.playcofrade.com/json/get_templos.php?id=(pasarid value here)").responseJSON { (responseData) -> Void in
        let swiftyJsonVar = JSON(responseData.result.value!)

        if let resData = swiftyJsonVar["templos"].arrayObject {
            self.arrRes = resData as! [[String:AnyObject]]
}

        var dict = self.arrRes
        self.completo.text = dict["nombre"]
我在最后一行得到一个错误,上面说

无法使用“String”类型的索引为“[[String:AnyObject]]”类型的值下标

我的JSON输出是

{ "templos": [
    {
    "id": "1",
    "nombre": "S. I. Catedral Basílica de la Encarnación",
    "descripcion": "Se encuentra dentro de los límites que marcaba la desaparecida muralla árabe sobre el solar de la primitiva mezquita aljama, el lugar donde los Reyes Católicos Isabel y Fernando ordenaron erigir un templo cristiano a los pocos días de conquistar la ciudad en 1487.\r\n\r\nSe caracteriza por tener una de las dos torres incompleta, popularmente haciendolo llamar entre los malagueños como la \"manquita\".",
    "antiguedad": "1782",
    "estilo": "Arquitectura Renacentista",
    "calle": "Calle Molina Lario, 9, 29015",
    "latitud": "36.7201678",
    "longitud": "-4.419310600000017",
    "director": "Sr. Obispo, Mons. Jesús Catalá Ibáñez",
    "titulares": "En el Sagrario de la Santa Iglesia Catedral se encuentra el Santísimo Cristo Mutilado.",
    "horario": "Santa Iglesia Catedral:\r\n\r\n · Horarios de apertura\r\n -De lunes a viernes: de 9 a 19 h.\r\n -Sábados: de 9 a 20 h.\r\n -Domingos: de 8:30 a 20 h.\r\n\r\n · Misas\r\n -De lunes a sábado: 9:15 h. con rezo de Laudes\r\n -Vísperas de domingos y de festivos: 19 h.\r\n -Domingos y festivos: 9, 10, 11:30, 13 y 19 h.\r\n\r\n · Confesiones\r\n -Media hora antes de cada misa\r\n    -Visitas concertadas en taquilla\r\n    De lunes a viernes: de 10 a 18 h.\r\n    Sábados: de 10 a 17 h.\r\n    -Visitas no concertadas\r\n    Domingos: de 14 a 18 h.\r\n\r\nSagrario de la Catedral:\r\n\r\n · Horarios de apertura\r\n -De lunes a viernes: de 10:15 a 12:15 h. y de 18 a 19 h.\r\n -Sábados: de 10:15 a 12:15 h.\r\n -Domingos: de 9:30 a 13:30 h.\r\n\r\n · Misas\r\n -De lunes a viernes: 10:30, 11:30 y 18:30 h.\r\n -Sábados: 10:30 y 11:30 h.\r\n \r\n · Confesiones\r\n -Media hora antes de cada misa\r\n\r\n · Bodas\r\n -Sábados por la tarde\r\n\r\n · Visitas no concertadas\r\n -Domingos: de 9:30 a 13:30 h."
    }
    ],
    "success": 1
    }

您只需使用json结果并将标签填充为:

    Alamofire.request(.GET, "http://elpenitente.playcofrade.com/json/get_templos.php?id=(pasarid value here)").responseJSON { (responseData) -> Void in
            let swiftyJsonVar = JSON(responseData.result.value!)

            if let resData = swiftyJsonVar["templos"].array {
               self.completo.text = resDate[0]["nombre"].string
             }
})

您只需使用json结果并将标签填充为:

    Alamofire.request(.GET, "http://elpenitente.playcofrade.com/json/get_templos.php?id=(pasarid value here)").responseJSON { (responseData) -> Void in
            let swiftyJsonVar = JSON(responseData.result.value!)

            if let resData = swiftyJsonVar["templos"].array {
               self.completo.text = resDate[0]["nombre"].string
             }
})

您已经声明了您的目标,并发布了一些代码。那么你的代码怎么了?它如何不满足您的目标?它不能编译吗?运行时崩溃?给出错误的结果?具体点。更新,谢谢你的建议@duncac
arrRes
是一个字典数组,但是你做了
var dict=self.arrRes
,你试着像字典一样访问它。这是你的问题。因为你的
arrRes
是一个字典数组,所以你不能使用键值访问它。你可以发布你的
JSON
你已经声明了你的目标,并发布了一些代码。那么你的代码怎么了?它如何不满足您的目标?它不能编译吗?运行时崩溃?给出错误的结果?具体点。更新,谢谢你的建议@duncac
arrRes
是一个字典数组,但是你做了
var dict=self.arrRes
,你试着像字典一样访问它。这是你的问题。因为你的
arrRes
是一个字典数组,所以你不能使用键值访问它。你可以发布你的
JSON
什么url我在你的问题中看不到任何url吗?我从哪里得到JSON我不知道怎么做什么url我在你的问题中看不到任何url?我从哪里得到JSON我不知道怎么做