【问题标题】:How to parse json latitude and longitude via cell in swift如何在swift中通过单元格解析json纬度和经度
【发布时间】:2017-04-06 02:51:59
【问题描述】:

我正在使用 Swift-2 开发应用程序。我正在将 JSON 数据解析为表格视图。在点击一个单元格时,它会移动到另一个视图控制器并获取数据。一切正常,但问题是当我不知道如何从从服务器获取的 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 数据中

【问题讨论】:

  • 试试这个 item.objectAtIndex(index).objectForKey(piclat) as? NSNumber
  • 我会检查并回复谢谢您的回复

标签: ios json swift swift2 mkmapview


【解决方案1】:

我的问题得到了答案:

我只是将func didselect方法中的纬度和经度作为nsstring传递

在func didupdate定位方法中:

我只是将字符串转换成 double 像 Double(["latitude"])

这对我有用

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-01
    • 1970-01-01
    • 2011-01-01
    • 2020-07-20
    • 1970-01-01
    相关资源
    最近更新 更多