如何在R中使用JSON包时更改编码?
for (pageNum in 0:20) {
data <- fromJSON(paste0("https://api.hh.ru/vacancies?text=\"?????????\"&page=", pageNum))
vacanciesdf <- rbind(vacanciesdf, data.frame(
data$items$area$name,
data$items$salary$currency,
data$items$salary$from,
data$items$employer$name,
data$items$name,
data$items$snippet$requirement))
print(paste0("Upload pages:", pageNum + 1))
Sys.sleep(3)
}
Run Code Online (Sandbox Code Playgroud)
在英语中,在引入关键字时从API下载有效,但俄语中没有任何内容.我认为问题在于编码.但是如何安装UTF-8?
这些类型的问题很难重现,但使用“content GET”来应用 UTF-8 编码,然后“fromJSON”通常可以解决问题。
您的问题中提供的 URL 返回错误,因此此解决方案演示了主体,从您正在使用的 api 获取参数列表。
library(httr)
library(jsonlite)
URL <- "https://api.hh.ru/vacancies?describe_arguments=true"
text <- content(GET(URL), as = "text", encoding = "UTF-8")
data <- fromJSON(text)
Run Code Online (Sandbox Code Playgroud)
这将返回 UTF-8 编码的 JSON。
| 归档时间: |
|
| 查看次数: |
1281 次 |
| 最近记录: |