如何替换“意外的转义字符"?在R中 [英] How to replace "unexpected escaped character" in R

查看:145
本文介绍了如何替换“意外的转义字符"?在R中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试从Facebook URL中的字符对象中解析JSON时,出现了"fromJSON(data)中的错误:pos 130处意外的转义字符'\ o'".检查一下:

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

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

在尝试解析JSON之前,有什么方法可以替换此'\ o'字符吗?我尝试了gsub,但是它不起作用(或者我做错了什么).

Is there any way to replace this '\o' character before I try to parse JSON? I tried gsub but it didn't work (or i'm doing something wrong).

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

有人可以帮我这个忙吗?谢谢.

Can somebody hel me with this one? Thanks.

推荐答案

您需要在模式中转义\.

尝试

gsub('\\o',' ',data)

这篇关于如何替换“意外的转义字符"?在R中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆