Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- echo json_encode($resultArray);
- func parseJSON() {
- var jsonResult: NSMutableArray = NSMutableArray()
- do{
- jsonResult = try JSONSerialization.jsonObject(with: self.data as Data, options:JSONSerialization.ReadingOptions.allowFragments) as! NSMutableArray
- } catch let error as NSError {
- print(error)
- }
- var jsonElement: NSDictionary = NSDictionary()
- let locations: NSMutableArray = NSMutableArray()
- for i in 1...jsonResult.count
- {
- jsonElement = jsonResult[i-1] as! NSDictionary
- let location = LocationModel()
- if let name = jsonElement["Name"] as? String,
- let address = jsonElement["Address"] as? String,
- let latitude = jsonElement["Latitude"] as? String,
- let longitude = jsonElement["Longitude"] as? String
- {
- location.name = name
- location.address = address
- location.latitude = latitude
- location.longitude = longitude
- }
- locations.add(location)
- }
- DispatchQueue.main.async(execute: { () -> Void in
- self.delegate.itemsDownloaded(items: locations)
- })
- }
- var jsonResult: NSMutableArray = NSMutableArray()
- var jsonResult: NSArray = NSArray()
- jsonResult = try JSONSerialization.jsonObject(with: self.data as Data, options:JSONSerialization.ReadingOptions.allowFragments) as! NSMutableArray
- jsonResult = try JSONSerialization.jsonObject(with: self.data as Data, options:JSONSerialization.ReadingOptions.allowFragments) as! NSArray
- func parseJSON() {
- var jsonResult: NSArray = NSArray()
- do{
- jsonResult = try JSONSerialization.jsonObject(with: self.data as Data, options:JSONSerialization.ReadingOptions.allowFragments) as! NSArray
- } catch let error as NSError {
- print(error)
- }
- var jsonElement: NSDictionary = NSDictionary()
- let locations: NSMutableArray = NSMutableArray()
- for i in 1...jsonResult.count
- {
- jsonElement = jsonResult[i-1] as! NSDictionary
- let location = LocationModel()
- if let name = jsonElement["Name"] as? String,
- let address = jsonElement["Address"] as? String,
- let latitude = jsonElement["Latitude"] as? String,
- let longitude = jsonElement["Longitude"] as? String
- {
- location.name = name
- location.address = address
- location.latitude = latitude
- location.longitude = longitude
- }
- locations.add(location)
- }
- DispatchQueue.main.async(execute: { () -> Void in
- self.delegate.itemsDownloaded(items: locations)
- })
- }
- func parseJSON() {
- var jsonResult: NSArray
- do {
- jsonResult = try JSONSerialization.jsonObject(with: data as Data) as! NSArray
- } catch let error as NSError {
- print(error)
- return
- }
- ...
- }
- func parseJSON() {
- var jsonResult: [[String: Any]] // this is an array of dictionaries
- do {
- jsonResult = try JSONSerialization.jsonObject(with: data as Data) as! [[String: Any]]
- } catch let error as NSError {
- print(error)
- return
- }
- for jsonElement in jsonResult {
- if let name = jsonElement["Name"] as? String,
- let address = jsonElement["Address"] as? String,
- let latitude = jsonElement["Latitude"] as? String,
- let longitude = jsonElement["Longitude"] as? String
- {
- let location = LocationModel()
- location.name = name
- location.address = address
- location.latitude = latitude
- location.longitude = longitude
- locations.add(location) // or, if you defined `locations` to be a Swift array, `locations.append(location)`
- }
- }
- ...
- }
Add Comment
Please, Sign In to add comment