R语言:使用jsonlite

时间:2018-02-13 16:26:00

标签: json r url jsonlite

我正在使用R,我有一个网页,希望JSON格式的数据能够返回我想要的内容。但是,当我设置JSON对象并将其粘贴到我的URL时,R会将转义字符(反斜杠)添加到JSON对象中的双引号。我想删除反斜杠:

R> library(jsonlite)
R> lst <- list(key = 'value')
R> json <- toJSON(lst)
R> url <- paste0('http://some.url.com?data=', json)

R> url
[1] "http://some.url.com?data={\"key\":[\"value\"]}"

我的sessionInfo()

R version 3.4.2 (2017-09-28)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.5 LTS

Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.0
LAPACK: /usr/lib/lapack/liblapack.so.3.0

locale:
 [1] LC_CTYPE=en_US.UTF-8          LC_NUMERIC=C                 
 [3] LC_TIME=en_US.UTF-8           LC_COLLATE=en_US.UTF-8       
 [5] LC_MONETARY=sv_SE.UTF-8       LC_MESSAGES=en_US.UTF-8      
 [7] LC_PAPER=sv_SE.UTF-8          LC_NAME=sv_SE.UTF-8          
 [9] LC_ADDRESS=sv_SE.UTF-8        LC_TELEPHONE=sv_SE.UTF-8     
[11] LC_MEASUREMENT=sv_SE.UTF-8    LC_IDENTIFICATION=sv_SE.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] XML_3.98-1.9 jsonlite_1.5 httr_1.3.1   rj_2.1.0-13 

loaded via a namespace (and not attached):
[1] compiler_3.4.2 R6_2.2.2       tools_3.4.2    rj.gd_2.1.0-2 

0 个答案:

没有答案