php - json parsing swift alamofire
I am fetching data from mysql and php with alamofire data is encoded in json which is fetching fine in response now i want to decode and display in tableview how to parse data and display in tableview i have search many examples but not found my solution how to decode and display data in tableview.
<?php
if($_SERVER['REQUEST_METHOD'] == "GET")
{
$conn = mysqli_connect("localhost","id15123058_root2","Ioscrud/12345","id15123058_imageupload");
$query = mysqli_query($conn,"SELECT * FROM `ioscrud`");
while($fetch = mysqli_fetch_array($query))
{
$temp[] = $fetch;
}
$json['jobs'] = $temp;
$jsonformat = json_encode($json);
echo ($jsonformat);
}
?>
This is my php code
import UIKit
class Product:Decodable
{
var name:String
var email:String
var password:String
init(name:String,email:String,password:String) {
self.name = name
self.email = email
self.password = password
}
}
This is class
import UIKit
import Alamofire
class TableViewController: UITableViewController {
@IBOutlet var tableview: UITableView!
var product = [Product]()
override func viewDidLoad() {
super.viewDidLoad()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem
}
// MARK: - Table view data source
// override func numberOfSections(in tableView: UITableView) -> Int {
// // #warning Incomplete implementation, return the number of sections
// return product.count
// }
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return product.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableViewCell
let url = "https://jobportal475.000webhostapp.com/IosCrud/viewData.php"
AF.request(url,method: .get).response
{response in
debugPrint(response)
if response.data != nil
{
debugPrint(response)
}
}
cell.nameLabel.text = product[indexPath.row].name
cell.emailLabel.text = product[indexPath.row].email
cell.passwordLabel.text = product[indexPath.row].password
return cell
}
}
Answer
Solution:
There is library for directions you can use it if you want https://github.com/akexorcist/GoogleDirectionLibrary
Or you can use this
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?
saddr="+latitude_cur+","+longitude_cur+"&daddr="+latitude+","+longitude));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addCategory(Intent.CATEGORY_LAUNCHER );
intent.setClassName("com.google.android.apps.maps",
"com.google.android.maps.MapsActivity");
startActivity(intent)
Source