【问题标题】:How to iterate through Response from Twitter Search API如何迭代来自 Twitter 搜索 API 的响应
【发布时间】:2015-03-31 15:57:23
【问题描述】:

我正在使用以下适用于

的代码

https://api.twitter.com/1.1/statuses/home_timeline.json?

但不适用于以下搜索 URL:

https://api.twitter.com/1.1/search/tweets.json?q=kifi%20sales

代码是:

if (response.IsSuccessStatusCode)
{
    JToken statuses = await response.Content.ReadAsAsync<JToken>();
    Console.WriteLine("Most recent statuses from home timeline twitter account for the given search:");
    Console.WriteLine();
    foreach (var status in statuses)
    {
        Console.WriteLine("   {0}", status["text"]);
        Console.WriteLine();
    }
}

我得到的错误是Cannot access child value on Newtonsoft.Json.Linq.JProperty,换句话说,它看不到“文本”属性。

有人知道我做错了什么吗?

【问题讨论】:

    标签: c# json twitter json.net


    【解决方案1】:

    Search API has a subtly different response 来自 home_timeline API。

    {
      "statuses": [
        {
          "coordinates": null,
          "favorited" ...
    

    我建议使用库来使事情尽可能透明。

    【讨论】:

    • 嗨,我的帖子可能不清楚我实际上是在询问 foreach 循环代码应该是什么(一旦我将状态放入 JToken 中)。
    猜你喜欢
    • 2019-03-13
    • 1970-01-01
    • 1970-01-01
    • 2016-07-03
    • 2023-01-23
    • 2017-02-10
    • 1970-01-01
    • 2014-10-24
    • 1970-01-01
    相关资源
    最近更新 更多