raj kumar raj kumar - 16 days ago 5
JSON Question

How to parse json latitude and longitude via cell in swift

I am developing an app using Swift-2. I am parsing JSON data to table view. On tapping a cell, it moves to another view controller and fetching data. Everything works fine but the problem is when I don't know how to parse latitude and longitude from JSON data which am getting from the server.

Code in my first controller:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

TableView.deselectRowAtIndexPath(indexPath, animated: true)

let tripcontroller = self.storyboard?.instantiateViewControllerWithIdentifier("UpcomingController") as! UpcomingController

let strbookdetail : NSString=arrDict[indexPath.row] .valueForKey("customer_name") as! NSString

let strdrop : NSString=arrDict[indexPath.row] .valueForKey("customer_phno") as! NSString

tripcontroller.dataFromBeforeVC = ["strbookdetail":strbookdetail as String, "strdrop":strdrop as String]

navigationController?.pushViewController(tripcontroller, animated: true)}

//it helps when tapping the cell moves to other controller and fetching data


code in second controller:

//here i wrote some functions and methods for updating current location and fetching some data when tapped a cell

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

//i know that here only i need to parse json lat and long so HELP me to parse


Data from the server:

{item:[{

picklat:"9.322334",

picklong:"78.24524",

droplat:"9.253634",

droplong:"78.56245"

},{

picklat:"8.245234",

picklong:"67.456434",

droplat:"8.4567865",

groplong:"67.465785"

}]}


from that JSON data i want show annotation with pick and drop

Answer

I got a answer for my question:

i just pass the latitude and longitude in func didselect method as nsstring

In func didupdate location method:

I just convert the string into double like Double(["latitude"])

This works for me