【问题标题】:issue importing json file in r在 r 中导入 json 文件的问题
【发布时间】:2020-03-07 20:41:43
【问题描述】:

我正在尝试从这个 api https://api.ycombinator.com/companies/export.json?callback=true 导入数据

我收到以下错误:

 Error in parse_con(txt, bigint_as_char) lexical error: invalid char in json text.
                                   setupCompanies([{"name":"Parake
                 (right here) ------^

我认为错误是因为表情符号,所以我将文件下载为文本并进行了手动删除。它没有工作

【问题讨论】:

    标签: r json jsonlite


    【解决方案1】:

    从您的 URL 中删除 ?callback=true,它可以正常工作:

    aa <- jsonlite::fromJSON("https://api.ycombinator.com/companies/export.json")
    str(aa)
    # 'data.frame': 2055 obs. of  8 variables:
    #  $ name       : chr  "Parakey" "Dinesafe" "Pengram" "Demeanor.co" ...
    #  $ url        : chr  "http://parakey.com" "https://dinesafe.org" "http://pengramar.com" "https://demeanor.co" ...
    #  $ batch      : chr  "s2005" "s2018" "w2019" "s2018" ...
    #  $ vertical   : chr  NA "B2B" "Augmented Reality" "Media" ...
    #  $ description: chr  "" "We crowdsource food poisoning reports and help detect and prevent outbreaks." "Pengram provides indoor navigation in augmented reality on your phone. " "Now part of thentwrk.com" ...
    #  $ dead       : logi  FALSE FALSE FALSE FALSE FALSE FALSE ...
    #  $ has_ff     : logi  NA FALSE FALSE FALSE FALSE FALSE ...
    #  $ all_ff     : logi  NA FALSE FALSE FALSE FALSE FALSE ...
    

    我猜测“回调 API”正在设置返回值,因此它实际上是一个函数调用(即setupCompanies(...)),而不仅仅是数据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-29
      • 1970-01-01
      • 1970-01-01
      • 2019-02-17
      • 2016-11-15
      相关资源
      最近更新 更多