英文:
How to deal with Error in fromJSON("transcripts_ru_2023-01-16.json") : not all data was parsed (0 chars were parsed out of a total of 30 chars)?
问题
我正在尝试在R中加载一个JSON文件,但我不断收到以下错误:
Error in fromJSON("transcripts_ru_2023-01-16.json") :
not all data was parsed (0 chars were parsed out of a total of 30 chars)
这是我正在使用的代码:
install.packages("rjson")
library("rjson")
data <- fromJSON("transcripts_ru_2023-01-16.json")
数据可在此处获取:https://drive.google.com/file/d/1MeKgd2hyicXjuZH1JnhFxNyFwpBXaFoj/view?usp=sharing
英文:
I am trying to load a JSON file in R
, but I keep receiving the following error:
Error in fromJSON("transcripts_ru_2023-01-16.json") :
not all data was parsed (0 chars were parsed out of a total of 30 chars)
Here is the code I am using:
install.packages("rjson")
library("rjson")
data <- fromJSON("transcripts_ru_2023-01-16.json")
Data available here: https://drive.google.com/file/d/1MeKgd2hyicXjuZH1JnhFxNyFwpBXaFoj/view?usp=sharing
答案1
得分: 1
这是一个以换行符分隔的 JSON 数据;每行都是一个独立的 JSON 对象。
由于数据相对较小,你可以使用类似下面的方式将其全部加载到内存中:
tscr <- jsonlite::stream_in(file("transcripts_en_2023-01-16.json"))
将其转换为 tibble 格式:
tibble::as_tibble(tscr)
创建日期:2023-07-17,使用 reprex v2.0.2 工具生成。
英文:
It's a newline-delimited JSON; each individual line is a separate JSON object.
As it's quite small for what it is, you can probably load it all to memory with something like this:
tscr <- jsonlite::stream_in(file("transcripts_en_2023-01-16.json"))
#> opening file input connection.
#> Found 500 records... /.../ Imported 9349 records. Simplifying...
#> closing file input connection.
tibble::as_tibble(tscr)
#> # A tibble: 9,349 × 10
#> date persons transcript_unfiltered kremlin_id place title teaser tags
#> <chr> <list> <chr> <int> <chr> <chr> <chr> <lis>
#> 1 1999-12-31… <list> Vladimir Putin: Dear… 22280 "The… New … "" <chr>
#> 2 1999-12-31… <list> Vladimir Putin: Good… 22326 "The… Addr… "" <chr>
#> 3 1999-12-31… <list> Boris Yeltsin: Dear … 24080 "The… Stat… "" <chr>
#> 4 2000-01-04… <list> Question: Mr Putin, … 24377 "Mos… Inte… "" <chr>
#> 5 2000-01-11… <list> Vladimir Putin: Dear… 24116 "Sta… Spee… "" <chr>
#> 6 2000-01-15… <list> Sergei Dorenko: Mr. … 24123 "" Inte… "" <chr>
#> 7 2000-01-18… <list> Question: You have s… 24125 "Mos… Conv… "" <chr>
#> 8 2000-01-18… <list> Vladimir Putin: I am… 24124 "Mos… A sp… "" <chr>
#> 9 2000-01-21… <list> Vladimir Putin: Dist… 21505 "Mos… Open… "" <chr>
#> 10 2000-01-23… <list> Nikolai Svanidze: Th… 24126 "" Inte… "" <chr>
#> # ℹ 9,339 more rows
#> # ℹ 2 more variables: transcript_filtered <chr>, wordlist <list>
<sup>Created on 2023-07-17 with reprex v2.0.2</sup>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论