我開始轉義字符在JSON數據
mentions = GET(final_url, sig)
json = content(mentions)
下一行是
json2 = jsonlite::fromJSON(toJSON(json))
給錯誤
我的代碼崩潰...
Error: lexical error: invalid character inside string.
Foundation and 42nd President of the United States. Follow
(right here) ------^
我處理與一些JSON數據。 它的一小塊看起來像這樣。也就是說,這是我的變量「json」的輸出。
Lots of JSON before this....
$statuses[[99]]$retweeted_status$user$location
[1] "New York, NY"
$statuses[[99]]$retweeted_status$user$description
[1] "Founder, Clinton Foundation and 42nd President \003of the United States. Follow @clintonfdn for \003more on my work around the world."
$statuses[[99]]$retweeted_status$user$url
[1] "http://t.co/gI8TIlAJHk"
正如你所看到的,在JSON數據中嵌入了一個轉義字符\ 003。
我正在處理同一個文件中的數百條好信息,但是現在可能會發生這種情況。當然這次它發生在「描述」中,但它可能發生在推文中,位置中,描述中等。
有沒有一種方法可以在嘗試執行jsonlite之前從JSON中「清除」轉義字符? fromJSON(toJSON())來避免我的代碼在這裏崩潰?
我的一個文本編輯器(在Mac上)有一個「刪除NonASCII字符」工具。您可以嘗試通過這樣的編輯步驟傳遞您的JSON文件。 –