How to replace "unexpected escaped character" in R

When I try to parse JSON from a character object from a Facebook URL, I got the message "Error in fromJSON (data): unexpected escaped character" \ o "at position 130". Check this:

library(RCurl)
library(rjson)
data <- getURL("https://graph.facebook.com/search?q=multishow&type=post&limit=1500", cainfo="cacert.perm")
fbData <- fromJSON(data)
Error in fromJSON(data) : unexpected escaped character '\o' at pos 130

#with RSONIO also error
> fbData <- fromJSON(data)
Erro em fromJSON(content, handler, default.size, depth, allowComments,  : 
invalid JSON input

Is there a way to replace this '\ o' character before I try to parse JSON? I tried gsub but it did not work (or am I doing something wrong).

datafixed <- gsub('\o',' ',data)
Error: '\o' is an unrecognized escape sequence in string starting with "\o"

Can anyone help me with this? Thank.

+5
source share
2 answers

You need to avoid \in your template.

Try

gsub('\\o',' ',data)
+3
source

You could do

fbData <- fromJSON(data,unexpected.escape = "keep")

you will see a warning

Warning message:
In fromJSON(individual_page, unexpected.escape = "keep") :
unexpected escaped character '\m' at pos 10. Keeping value.

if you want, you can suppress the warning using

suppressWarnings(fromJSON(data,unexpected.escape = "keep"))

negative.escape: . "", "" ""; ,

- http://cran.r-project.org/web/packages/rjson/rjson.pdf

+1

All Articles