【问题标题】:not able print twitter response on label in table view无法在表格视图的标签上打印 twitter 响应
【发布时间】:2019-01-06 07:50:35
【问题描述】:

我收到了 twitter v 11 api 响应,我填满了我的数组,但我无法在 tableview 上打印,这是响应

[(Swift.ImplicitlyUnwrappedOptional<Any>.some(<__NSArrayM 0x600000842520>(
{
    contributors = "";
    coordinates = "";
    "created_at" = "Thu Jul 12 11:49:57 +0000 2018";
    entities =     {
        hashtags =         (
        );
        media =         (
                        {
                "display_url" = "pic.twitter.com/IJtq6aLM7K";
                "expanded_url" = "";
                id = 1017375504448479232;
                "id_str" = 1017375504448479232;
                indices =                 (
                    12,
                    35
                );
                "media_url" = "";
                "media_url_https" = "";
                sizes =                 {
                    large =                     {
                        h = 1820;
                        resize = fit;
                        w = 2048;
                    };
                    medium =                     {
                        h = 1067;
                        resize = fit;
                        w = 1200;
                    };
                    small =                     {
                        h = 604;
                        resize = fit;
                        w = 680;
                    };
                    thumb =                     {
                        h = 150;
                        resize = crop;
                        w = 150;
                    };
                };
                type = photo;
                url = "";
            }
        );
        symbols =         (
        );
        urls =         (
        );
        "user_mentions" =         (
        );
    };
    "extended_entities" =     {
        media =         (
                        {
                "display_url" = "pic.twitter.com/IJtq6aLM7K";
                "expanded_url" = "";
                id = 1017375504448479232;
                "id_str" = 1017375504448479232;
                indices =                 (
                    12,
                    35
                );
                "media_url" = "";
                "media_url_https" = "";
                sizes =                 {
                    large =                     {
                        h = 1820;
                        resize = fit;
                        w = 2048;
                    };
                    medium =                     {
                        h = 1067;
                        resize = fit;
                        w = 1200;
                    };
                    small =                     {
                        h = 604;
                        resize = fit;
                        w = 680;
                    };
                    thumb =                     {
                        h = 150;
                        resize = crop;
                        w = 150;
                    };
                };
                type = photo;
                url = "";
            }
        );
    };
    "favorite_count" = 0;
    favorited = 0;
    geo = "";
    id = 1017375507174719488;
    "id_str" = 1017375507174719488;
    "in_reply_to_screen_name" = "";
    "in_reply_to_status_id" = "";
    "in_reply_to_status_id_str" = "";
    "in_reply_to_user_id" = "";
    "in_reply_to_user_id_str" = "";
    "is_quote_status" = 0;
    lang = fr;
    place = "";
    "possibly_sensitive" = 0;
    "retweet_count" = 0;
    retweeted = 0;
    source = "";
    text = "Tweet Tweet";
    truncated = 0;

这是我填写数组的代码

从这段代码中我得到了响应

var timeline = (FHSTwitterEngine.shared().getTimelineForUser(FHSTwitterEngine.shared().authenticatedUsername, isID: true, count: 10), terminator: "")

现在我像这样填充我的数组

 var serviceData : [AnyObject]=[]
 let timelinedata = [timeline] as [AnyObject]
        serviceData = (timelinedata)
        print(serviceData)

我在服务数据中得到了完整的响应,现在我正在尝试在表格视图中的标签上打印,如下所示

let retweerCount = serviceData[indexPath.row]["retweet_count"]
            cell.lblRetweet.text = retweerCount as? String

我无法打印,谁能帮我解决这个问题

【问题讨论】:

  • 改变你的数组格式 [[String:Any]]()
  • 是的,我已经做到了,现在正在检查
  • @karthikeyan 它给了我相同的任何其他解决方案崩溃
  • @Vishal 我认为 retweerCount 是整数而不是字符串,所以请使用此代码 cell.lblRetweet.text = "\(retweerCount as? Int ?? 0)"
  • @chiragshah 让我试着告诉你

标签: ios swift twitterkit fhs-twitter-engine


【解决方案1】:

我认为retweerCountinteger 而不是string 所以使用下面的代码。

cell.lblRetweet.text = "\(retweerCount as? Int ?? 0)"

【讨论】:

  • 我还有一个问题,如果想从响应中打印姓名,那么我无法打印
  • @Vishal 你能给我参数名吗?
  • 是的,但我无法做到这一点,你必须安装 pod FHSTwitterEngine,如上所述,我提到我正在从第三方库获得响应
  • @Vishal 我说的是响应参数名称意味着您需要为 ex 提取哪个参数。转推数
  • 是的,我想提取转发计数和收藏计数名称屏幕名称、文本、创建日期
猜你喜欢
  • 2020-12-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多