Guest User

Untitled

a guest
Feb 14th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. echo json_encode($resultArray);
  2.  
  3. func parseJSON() {
  4. var jsonResult: NSMutableArray = NSMutableArray()
  5.  
  6. do{
  7. jsonResult = try JSONSerialization.jsonObject(with: self.data as Data, options:JSONSerialization.ReadingOptions.allowFragments) as! NSMutableArray
  8. } catch let error as NSError {
  9. print(error)
  10. }
  11.  
  12. var jsonElement: NSDictionary = NSDictionary()
  13. let locations: NSMutableArray = NSMutableArray()
  14.  
  15. for i in 1...jsonResult.count
  16. {
  17. jsonElement = jsonResult[i-1] as! NSDictionary
  18.  
  19. let location = LocationModel()
  20.  
  21. if let name = jsonElement["Name"] as? String,
  22. let address = jsonElement["Address"] as? String,
  23. let latitude = jsonElement["Latitude"] as? String,
  24. let longitude = jsonElement["Longitude"] as? String
  25. {
  26. location.name = name
  27. location.address = address
  28. location.latitude = latitude
  29. location.longitude = longitude
  30.  
  31. }
  32. locations.add(location)
  33. }
  34. DispatchQueue.main.async(execute: { () -> Void in
  35.  
  36. self.delegate.itemsDownloaded(items: locations)
  37.  
  38. })
  39. }
  40.  
  41. var jsonResult: NSMutableArray = NSMutableArray()
  42.  
  43. var jsonResult: NSArray = NSArray()
  44.  
  45. jsonResult = try JSONSerialization.jsonObject(with: self.data as Data, options:JSONSerialization.ReadingOptions.allowFragments) as! NSMutableArray
  46.  
  47. jsonResult = try JSONSerialization.jsonObject(with: self.data as Data, options:JSONSerialization.ReadingOptions.allowFragments) as! NSArray
  48.  
  49. func parseJSON() {
  50. var jsonResult: NSArray = NSArray()
  51. do{
  52. jsonResult = try JSONSerialization.jsonObject(with: self.data as Data, options:JSONSerialization.ReadingOptions.allowFragments) as! NSArray
  53. } catch let error as NSError {
  54. print(error)
  55. }
  56.  
  57. var jsonElement: NSDictionary = NSDictionary()
  58. let locations: NSMutableArray = NSMutableArray()
  59.  
  60. for i in 1...jsonResult.count
  61. {
  62. jsonElement = jsonResult[i-1] as! NSDictionary
  63.  
  64. let location = LocationModel()
  65.  
  66. if let name = jsonElement["Name"] as? String,
  67. let address = jsonElement["Address"] as? String,
  68. let latitude = jsonElement["Latitude"] as? String,
  69. let longitude = jsonElement["Longitude"] as? String
  70. {
  71.  
  72. location.name = name
  73. location.address = address
  74. location.latitude = latitude
  75. location.longitude = longitude
  76.  
  77. }
  78.  
  79. locations.add(location)
  80.  
  81. }
  82. DispatchQueue.main.async(execute: { () -> Void in
  83.  
  84. self.delegate.itemsDownloaded(items: locations)
  85.  
  86. })
  87. }
  88.  
  89. func parseJSON() {
  90. var jsonResult: NSArray
  91.  
  92. do {
  93. jsonResult = try JSONSerialization.jsonObject(with: data as Data) as! NSArray
  94. } catch let error as NSError {
  95. print(error)
  96. return
  97. }
  98.  
  99. ...
  100. }
  101.  
  102. func parseJSON() {
  103. var jsonResult: [[String: Any]] // this is an array of dictionaries
  104.  
  105. do {
  106. jsonResult = try JSONSerialization.jsonObject(with: data as Data) as! [[String: Any]]
  107. } catch let error as NSError {
  108. print(error)
  109. return
  110. }
  111.  
  112. for jsonElement in jsonResult {
  113. if let name = jsonElement["Name"] as? String,
  114. let address = jsonElement["Address"] as? String,
  115. let latitude = jsonElement["Latitude"] as? String,
  116. let longitude = jsonElement["Longitude"] as? String
  117. {
  118. let location = LocationModel()
  119. location.name = name
  120. location.address = address
  121. location.latitude = latitude
  122. location.longitude = longitude
  123. locations.add(location) // or, if you defined `locations` to be a Swift array, `locations.append(location)`
  124. }
  125. }
  126. ...
  127. }
Add Comment
Please, Sign In to add comment