如何使用swift3从alamofire响应中获取字典数组的值 [英] How to get values of an array of dictionary from alamofire response using swift3

查看:163
本文介绍了如何使用swift3从alamofire响应中获取字典数组的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Alamofire和swift3从json响应下方提取翻译"数组文本"和诗句"数组"verse_key"数据.

I'm trying to extract "translations" Array "text" and "verses" array "verse_key" data from below json response using Alamofire and swift3.

{
  "verses": [
    {
      "id": 1,
      "verse_number": 1,
      "chapter_id": 1,
      "verse_key": "1:1",
      "text_madani": "بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ",
      "text_indopak": "بِسْمِ اللّٰهِ الرَّحْمٰنِ الرَّحِيْمِ",
      "text_simple": "بسم الله الرحمن الرحيم",
      "juz_number": 1,
      "hizb_number": 1,
      "rub_number": 1,
      "sajdah": null,
      "sajdah_number": null,
      "page_number": 1,
      "audio": {
        "url": "versesAbdulBaset/Mujawwad/mp3/001001.mp3",
        "duration": 6,
      
        ],
        "format": "mp3"
      },
      "translations": [
        {
          "id": 102574,
          "language_name": "english",
          "text": "In the name of Allah, the Beneficent, the Merciful.",
          "resource_name": "Shakir",
          "resource_id": 21
        }
      ],
            }
  ],
  "meta": {
    "current_page": 1,
    "next_page": null,
    "prev_page": null,
    "total_pages": 1,
    "total_count": 7
  }
}

我是新手,我无法找到实现此目标的方法.如何获取"translations"数组"text"和"verses"数组"verse_key"的值? 谢谢前进

I'm new to swift and I can't find a way to achieve this. How can I get the values of "translations" Array "text" and "verses" array "verse_key" ? thanks advance

推荐答案

使用swiftyJSON.

Use swiftyJSON.

 switch response.result{
    case .success(let data) :
    let json = JSON(data)
    let verses = json["verses"].Stringvalue
    print(verses)  //get all verses
    print(verses["verse_key"].Stringvalue)  // get "verse_key" 
    break

您可以通过提供键名从此json中获取每个值.如果要获取诗歌",请使用json ["verses"].

You can take each values from this json by giving the key names. If you want to get the "verses" , use json["verses"].

这篇关于如何使用swift3从alamofire响应中获取字典数组的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆