json - lexical error: inside a string, '\' occurs before a character / Using jsonlite in R -
lately error if try parse json response google.
lexical error: inside string, '\' occurs before character may not. [sicgcmciag?kaq@i@kbkbgdgdoj]\ihgdmdi@k@e?iagagaicgegeigimos (right here) ------^
the string viewed in browser send google looks (i shortened it):
[sicgcmciag?kaq@i@kbkbgdgdoj]\\ihgdmdi@k@e?
this code i´m using
route_doc <- geturl(route) route_response <- fromjson(route_doc)
somehow jsonlite hangs here. can parse response google?
after investigating bit: crash happens if poly line entry contains backslash character
"polyline" : { "points" : "qv{uhwlni@r?" },
thank you!
update: i´m using code json response google:
route_from="köln" route_to="hamburg" get_route_url<-function(origin, destination, avoid,mode, alternatives, key, return.call = "json") { root<-"https://maps.googleapis.com/maps/api/directions/" u<-paste(root, return.call, "?origin=", origin, "&destination=",destination, "&avoid=",avoid, "&mode=", mode, "&alternatives=",alternatives, "&key=",key, sep = "") return(urlencode(u)) } route<-get_route_url(route_from, route_to, "highways", "driving", "true",mykey) route_doc <- geturl(route) route_response <- fromjson(route_doc)
and error example in polyline:
lexical error: inside string, '\' occurs before character may not. uhiani@@l@hbhbhbddfdbdb`@@t@@\g" }, (right here) ------^
google's api returns response in json, don't need 'doc' using geturl
, because fromjson
can read json directly
so call fromjson
on route
object
route_response <- fromjson(route)
and see routes
library(googleway) mapkey <- 'my_map_key' df <- data.frame(polyline = route_response$routes$overview_polyline$points) google_map(key = mapkey) %>% add_polylines(data = df, polyline = "polyline")
Comments
Post a Comment