Guest User

Untitled

a guest
Nov 23rd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. {
  2. "article": [
  3. {
  4. "header": "mindshare payment",
  5. "items": [
  6. {
  7. "title": "Applications workforce",
  8. "text": "Nulla molestiae aliquid natus libero placeat fugit recusandae tempora et."
  9. }
  10. ]
  11. }
  12. ]
  13. }
  14.  
  15. if let result = response.result.value as? [String: Any],
  16. let articleArray = result["article"] as? [[String: Any]],
  17. let main = articleArray["items"] as? [[String: Any]] {
  18. for obj in main {
  19. guard
  20. let title = obj["title"] as? String,
  21. let text = obj["text"] as? String,
  22. else {
  23. return
  24. }
  25. let struct = Articles(title: title, text: text)
  26. }
  27.  
  28. }
  29.  
  30. request(YOUR_URL, method: .get).responseJSON { response in
  31.  
  32. if response.result.isSuccess {
  33. print("Response success")
  34.  
  35. let yourJSON : JSON = JSON(response.result.value!)
  36.  
  37. if yourJSON != JSON.null {
  38.  
  39. print("Success: Json not nil")
  40.  
  41. self.title = yourJSON["article"]["title"].string
  42. self.text = yourJSON["article"]["text"].string
  43.  
  44. } else {
  45. print("Not success: Json nil")
  46. }
  47.  
  48. } else {
  49. print("Error: (String(describing: response.result.error))")
  50. }
  51. }
  52.  
  53. if let result = response.result.value as? [String: Any],
  54. let articleArray = result["article"] as? [[String: Any]] {
  55. articleArray.forEach { (obj: [[String: Any]]) in
  56. guard let title = obj["title"] as? String,
  57. let text = obj["text"] as? String,
  58. else { return }
  59. let struct = Articles(title: title, text: text)
  60. }
  61. }
Add Comment
Please, Sign In to add comment