[英]How to parse json latitude and longitude via cell in swift
I am developing an app using Swift-2. 我正在使用Swift-2开发应用程序。 I am parsing JSON data to table view.
我正在将JSON数据解析为表视图。 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.
一切正常,但问题是当我不知道如何从服务器获取的JSON数据中解析纬度和经度时。
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 从该JSON数据中,我想通过拖放显示注释
I got a answer for my question: 我的问题得到了答案:
i just pass the latitude and longitude in func didselect method as nsstring 我只是在func didselect方法中将纬度和经度传递为nsstring
In func didupdate location method: 在func didupdate定位方法中:
I just convert the string into double like Double(["latitude"]) 我只是将字符串转换成Double一样Double([“ latitude”])
This works for me 这对我有用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.