如何通过 swift 中的单元格解析 json 纬度和经度
How to parse json latitude and longitude via cell in swift
我正在使用 Swift-2 开发应用程序。我正在将 JSON 数据解析为 table 视图。在点击一个单元格时,它会移动到另一个视图控制器并获取数据。一切正常,但问题是当我不知道如何从从服务器获取的 JSON 数据中解析纬度和经度时。
我的第一个控制器中的代码:
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
第二个控制器中的代码:
//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
来自服务器的数据:
{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"
}]}
我想从那个 JSON 数据中选择显示注释
我的问题得到了答案:
我只是在func didselect方法中将纬度和经度作为nsstring传递
在 func didupdate location 方法中:
我只是像 Double(["latitude"])
一样将字符串转换成双精度
这对我有用
我正在使用 Swift-2 开发应用程序。我正在将 JSON 数据解析为 table 视图。在点击一个单元格时,它会移动到另一个视图控制器并获取数据。一切正常,但问题是当我不知道如何从从服务器获取的 JSON 数据中解析纬度和经度时。
我的第一个控制器中的代码:
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
第二个控制器中的代码:
//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
来自服务器的数据:
{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"
}]}
我想从那个 JSON 数据中选择显示注释
我的问题得到了答案:
我只是在func didselect方法中将纬度和经度作为nsstring传递
在 func didupdate location 方法中:
我只是像 Double(["latitude"])
一样将字符串转换成双精度这对我有用