jsonlite 包无法使用 ANSI 编码导入文件

jsonlite package not working to import file with ANSI encoding

我试图在 R 中导入一个 json 文件(下载的文件编码是 ANSI。),但出现以下错误:

> library(jsonlite)
> js <- url %>% 
+   read_html() %>%
+   html_text() 
> js <- jsonlite::fromJSON(js)
Error: lexical error: invalid bytes in UTF8 string.
          _name": "Av. Nossa Sra. de Fátima , 25",             "stop_i
                     (right here) ------^

可重现的例子:

url <- "https://jeap.rio.rj.gov.br/MOB/get_stops_details.rule?sys=MOB&INDICE=1"

library(rvest)
library(jsonlite)

js <- url %>% 
  read_html() %>%
  html_text() 

js <- jsonlite::fromJSON(js)
> sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=Portuguese_Brazil.1252  LC_CTYPE=Portuguese_Brazil.1252   
[3] LC_MONETARY=Portuguese_Brazil.1252 LC_NUMERIC=C                      
[5] LC_TIME=Portuguese_Brazil.1252  

read_html

中设置正确的编码
library(rvest)
library(jsonlite)

js <- url %>% 
  read_html(encoding = 'latin1') %>%
  html_text() 

js <- jsonlite::fromJSON(js)