簡體   English   中英

json 解析 swift alamofire

[英]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在 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);
}
?>

這是我的 php 代碼

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
    }
}

這是 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
    }
    
}

如果您想要https://github.com/akexorcist/GoogleDirectionLibrary ,可以使用方向庫


或者你可以使用這個

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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM