我正在尝试使用jsonlite将Google Maps方向API的结果弄平。如何在字符串的某些部分逃避反斜杠 - R
的结果是JSON格式,他们有这样的这里的一些章节:
\"polyline\" : {\n \"points\"
: \"[email protected]@?|@[email protected]@@D?F?D?\"\n
},\n
\"start_location\" : {\n
\"lat\" : -3.0831712,\n
\"polyline\" : {\n \"points\"
:
\"b}yQ`[email protected]@[email protected]@@[email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected]@@?
@@[email protected]@@[email protected]@@@@[email protected][email protected][email protected]?bBH\"\n },\n
\"start_location\" : {\n
在大多数然后
我有“\”的编码点,这反过来又使jsonlite与错误崩溃内
> fromJSON(out)
Error: lexical error: inside a string, '\' occurs before a character which it may not.
"points" : "rsuQnzomJhBD\@lAF" },
(right here) ------^
我需要如何后\"points\" : \
下面的代码我加倍逃逸\只是一对双引号内的一些方向用于获取JSON输出
origin="-3.06010901,-60.04375624"
destination="-3.0876276,-60.06031519"
mode="walking"
units="metric"
language="en-EN"
baseURL <- "https://maps.googleapis.com/maps/api/directions/json?"
callURL <- paste0(baseURL,"origin=", origin,
"&destination=", destination,
"&units=", tolower(units),
"&mode=", tolower(mode),
"&language=",language)
tmout=10
opts = RCurl::curlOptions(connecttimeout=tmout)
out <- RCurl::getURL(callURL, .opts = opts)
嗯,我还没有一个简单的答案来拉平这个输出到数据帧,但是从这篇文章[JSON包在R的一种有偏comparsion]实例我有如果您在使用谷歌地图API与RJSONIO::fromJSON(jsonOutput,unexpected.escape = "keep")
感谢
难道你不能以类似的方式阅读此[对此](http://stackoverflow.com/questions/24183007/is-it-possible-to-read-geojson-or-topojson-file-in- R到平局-A-等值线图)? –
@RomanLuštrik不幸的不是。 json输出只是将这些多段线编码为一个字段,您需要稍后对其进行解码,然后才能到达坐标。此json不是空间数据文件。我尝试了那里提出的解决方案,但没有奏效。谢谢。 – jcarlos
'dput(out)'将有助于重现错误。由于很难从头创建一个糟糕的字符串。 – Tensibai