在标签上打印指令后响应时出现问题

时间:2018-08-08 11:02:41

标签: ios swift instagram

我收到instagram帖子响应,但是从那以后,我将数组放入对象中,我的意思是主数组是数据,并且我是对象用户,并且我想打印full_name这是响应

回复

SUCCESS: {
    data =     (
                {
            attribution = "<null>";
            caption =             {
                "created_time" = 1533621008;
                from =                 {
                    "full_name" = "Mike Alpha";
                    id = 8376082973;
                    "profile_picture" = "";
                    username = mikealpha607;
                };
                id = 17952863989106568;
                text = Hi;
            };
            comments =             {
                count = 1;
            };
            "created_time" = 1533621008;
            filter = Normal;
            id = "1840468872962982375_8376082973";
            images =             {
                "low_resolution" =                 {
                    height = 320;
                    url = "";
                    width = 320;
                };
                "standard_resolution" =                 {
                    height = 640;
                    url = "https://scontent.cdninstagram.com/vp/adcc206df693d4d65c9b6f6b5ef7a016/5C024385/t51.2885-15/sh0.08/e35/s640x640/37867466_267564047306571_7531604489342550016_n.jpg";
                    width = 640;
                };
                thumbnail =                 {
                    height = 150;
                    url = "";
                    width = 150;
                };
            };
            likes =             {
                count = 2;
            };
            link = "https://www.instagram.com/p/BmKqLBRH0Hn/";
            location =             {
                id = 761100677398542;
                latitude = "23.102652628869";
                longitude = "72.595614227203";
                name = "PVR Cinemas, Motera, Ahmedabad";
            };
            tags =             (
            );
            type = image;
            user =             {
                "full_name" = "Mike Alpha";
                id = 8376082973;
                "profile_picture" = "";
                username = mikealpha607;
            };
            "user_has_liked" = 1;
            "users_in_photo" =             (
            );
        }

我正在获得用户对象,但不知道如何在标签上打印让我显示我的代码

代码

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! TestTableViewCell

        let createdTime = serviceData[indexPath.row]["created_time"]
        let timeinterval : TimeInterval = (createdTime as! NSString).doubleValue
        let dateFromServer = NSDate(timeIntervalSince1970:timeinterval)
        let dateFormater : DateFormatter = DateFormatter()
        dateFormater.dateFormat = "dd MMM yyyy"
        cell.lblDate.text = dateFormater.string(from: dateFromServer as Date)


        let instaResponse = serviceData[indexPath.row]["user"]
        print(instaResponse)  **Here I am getting user object response but i understand how to print on label**   
        return cell
    }

请帮助我理解这一点

请检查此新问题

    let imagePosts = serviceData[indexPath.row]["images"] as! [String:Any]
    let instaImage = imagePosts["standard_resolution"]
    let proimgurl1 = NSURL(string: instaImage as! String)
    cell.imgPost.image = UIImage(data: NSData(contentsOf: proimgurl1! as URL)! as Data)

我正在获取imageurl,但是当我传递到图像视图时会崩溃

1 个答案:

答案 0 :(得分:0)

您可以尝试

let instaResponse = serviceData[indexPath.row]["user"] as! [String:Any]
let fName = instaResponse["full_name"] as! String
cell.fnameLbl.text = fName  // suppose outlet is fnameLbl
printfName)

//

let imagePosts = serviceData[indexPath.row]["images"] as! [String:[String:Any]]
let instaImage = imagePosts["standard_resolution"]["url"] as! String