JSON 개체의 본문 문자열에서 내용을 추출하려고합니다. 문제는 큰 따옴표를 전달하여 모든 텍스트 정보를 추출 할 수 없다는 것입니다. 이 경우 텍스트가 필요합니다. "설명서를 검색하는 동안 매우 짜증나는 라이브러리 함수에 대한 링크와 관련하여 설명서에 오타가 있습니다!" 나는 여기에 내 코드를 넣어 어떤 하나 (") 대신 큰 따옴표를 전달하는이 욕심 정량에 도달 할 수있는 방법을 제안 할 수있는 경우, (여기 내가 사용 된 표현이다) 한R의 json 문자열에서 큰 따옴표로 텍스트 추출
body<- str_extract(json_file , 'body[^,]*\\s*').
감사합니다
귀하의 입력은 하나의 잘못 형성된 예를 가지고, 그래서 나는이 데이터의 나머지 부분에 작동 할 것이라고 거의 확신을 가지고있다. 그러나, 방법은 에 당신이 원하는는이 데이터를 얻을 수library(stringr)
json_file<- '{ "_id" : ObjectId("539163d7bd350003"), "login" : "vui", "id" : 369607, "avatar_url" : "https://avatars.mashupsusercontent.com/u/369607?", "gravatar_id" : "df8897ffebe16c5b0cd690925c63e190", "body":"There is a typo error in documentation regarding a link to a librarys function, which is quite irritating while browsing the documentation!","url" : "https://api.mashups.com/users/vui", "html_url" : "https://mashups.com/vui", "followers_url" : "https://api.mashups.com/users/vui/followers", "following_url" : "https://api.mashups.com/users/vui/following{/other_user}", "gists_url" : "https://api.mashups.com/users/vui/gists{/gist_id}", "starred_url" : "https://api.mashups.com/users/vui/starred{/owner}{/repo}", "subscriptions_url" : "https://api.mashups.com/users/vui/subscriptions", "organizations_url" : "https://api.mashups.com/users/vui/orgs", "repos_url" : "https://api.mashups.com/users/vui/repos", "events_url" : "https://api.mashups.com/users/vui/events{/privacy}", "received_events_url" : "https://api.mashups.com/users/vui/received_events", "type" : "User", "site_admin" : false, "org" : "amurath"}'
body<- str_extract(json_file , 'body[^,]*\\s*')
body
주어진 문자열은 유효한 JSON 개체가 아닙니다. 그래서 당신은 여전히 어떻게 든 JSONish 문자열입니다. 정의 할 수없는 경우를 제외하고 JSONish가 의미하는 바는 견적 패턴이 유효 할 수 있습니다. –
유효성이 검사 된 JSON 객체를 넣었습니다. 생각이 있다면 알려주세요! 감사합니다, 안부! – user3570187