如何使用swift3从alamofire响应中获取字典数组的值

编程入门 行业动态 更新时间:2024-10-24 22:27:12
本文介绍了如何使用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响应中获取字典数组的值

本文发布于:2023-11-26 17:27:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634506.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   如何使用   字典   alamofire

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!