2012-11-26 2 views
0

나는 선호하는 파이썬으로 시작하고 싶은 트위터 데이터의 덤프를 받았습니다. JSON을 만들지 않았으므로 StatusJSONImpl, UserJSONImplUserMentionEntityJSONImpl 지시어에 익숙하지 않습니다. 어떻게 해석 할 수 있습니까? 먼저 '깨끗하게'해야합니까, 아니면 json (또는 유사한 모듈)이 알아낼 수 있습니까? s, 나는 당신을 가정 ValueError: No JSON object could be decodedtwitter 데이터 덤프에서 json을 파싱하십시오.

StatusJSONImpl { 
    createdAt = Tue Sep 20 08: 31: 28 CST 2011, 
    id = 115946140620435456, 
    text = 'RT @williamsanches: 4? Dica: Sonhe sempre. Deus acredita no cora??o que sonha!', 
    source = 'web', 
    isTruncated = false, 
    inReplyToStatusId = -1, 
    inReplyToUserId = -1, 
    isFavorited = false, 
    inReplyToScreenName = 'null', 
    geoLocation = null, 
    place = null, 
    retweetCount = 3, 
    wasRetweetedByMe = false, 
    contributors = null, 
    annotations = null, 
    retweetedStatus = StatusJSONImpl { 
     createdAt = Tue Sep 20 08: 29: 50 CST 2011, 
     id = 115945729465401344, 
     text = '4? Dica: Sonhe sempre. Deus acredita no cora??o que sonha!', 
     source = 'web', 
     isTruncated = false, 
     inReplyToStatusId = -1, 
     inReplyToUserId = -1, 
     isFavorited = false, 
     inReplyToScreenName = 'null', 
     geoLocation = null, 
     place = null, 
     retweetCount = 3, 
     wasRetweetedByMe = false, 
     contributors = null, 
     annotations = null, 
     retweetedStatus = null, 
     userMentionEntities = [], 
     urlEntities = [], 
     hashtagEntities = [], 
     user = UserJSONImpl { 
      id = 54728012, name = 'William_Sanches', screenName = 'williamsanches', location = '', description = 'Professor Universitário, escritor e palestrante.', isContributorsEnabled = false, profileImageUrl = 'http://a1.twimg.com/profile_images/1533016174/msn_normal.jpg', profileImageUrlHttps = 'https://si0.twimg.com/profile_images/1533016174/msn_normal.jpg', url = 'http://www.williamsanches.com.br', isProtected = false, followersCount = 10905, status = null, profileBackgroundColor = 'EDECE9', profileTextColor = '634047', profileLinkColor = '088253', profileSidebarFillColor = 'c7c7c7', profileSidebarBorderColor = 'D3D2CF', profileUseBackgroundImage = true, showAllInlineMedia = false, friendsCount = 232, createdAt = Wed Jul 08 07: 56: 17 CST 2009, 
      favouritesCount = 1, 
      utcOffset = -14400, 
      timeZone = 'Santiago', 
      profileBackgroundImageUrl = 'http://a3.twimg.com/profile_background_images/125874404/tela-william-sanches.jpg', 
      profileBackgroundImageUrlHttps = 'https://si0.twimg.com/profile_background_images/125874404/tela-william-sanches.jpg', 
      profileBackgroundTiled = false, 
      lang = 'es', 
      statusesCount = 7499, 
      isGeoEnabled = false, 
      isVerified = false, 
      translator = false, 
      listedCount = 130, 
      isFollowRequestSent = false 
     } 
    }, 
    userMentionEntities = [UserMentionEntityJSONImpl { 
     start = 3, end = 18, name = 'William_Sanches', screenName = 'williamsanches', id = 54728012}], 
    urlEntities = [], 
    hashtagEntities = [], 
    user = UserJSONImpl { 
     id = 170132028, name = 'Andrezza Santiago', screenName = 'andrezzasancar', location = '', description = 'Uma pessoa que ama a vida e vive pra ser amada.Ama acima de tudo a DEUS,sua familia e seus amigos! Alguém alegre e de bem com a vida.', isContributorsEnabled = false, profileImageUrl = 'http://a1.twimg.com/profile_images/1505208968/DSC_0414_normal.JPG', profileImageUrlHttps = 'https://si0.twimg.com/profile_images/1505208968/DSC_0414_normal.JPG', url = 'null', isProtected = false, followersCount = 64, status = null, profileBackgroundColor = '642D8B', profileTextColor = '3D1957', profileLinkColor = 'FF0000', profileSidebarFillColor = '7AC3EE', profileSidebarBorderColor = '65B0DA', profileUseBackgroundImage = true, showAllInlineMedia = false, friendsCount = 330, createdAt = Sat Jul 24 09: 02: 05 CST 2010, 
     favouritesCount = 0, 
     utcOffset = -14400, 
     timeZone = 'Santiago', 
     profileBackgroundImageUrl = 'http://a0.twimg.com/profile_background_images/321379737/images__2_.jpg', 
     profileBackgroundImageUrlHttps = 'https://si0.twimg.com/profile_background_images/321379737/images__2_.jpg', 
     profileBackgroundTiled = true, 
     lang = 'pt', 
     statusesCount = 3129, 
     isGeoEnabled = true, 
     isVerified = false, 
     translator = false, 
     listedCount = 20, 
     isFollowRequestSent = false 
    } 
}​ 
+1

당신은 무엇을 시도 했습니까? –

+1

먼저 청소를해야 할 것 같아요. 'json'은 그것을 처리 할 수 ​​없을 것입니다. – jdotjdot

+1

이것은 거의 * all *에서 JSON처럼 보이지 않습니다 ... – tjvr

답변

0

수 아래의 문자열로 json.loads(s)를 사용

가 올바른 형식의 JSON 개체가,이 트릭 할 것 :

import json 

data = json.loads(json_object) 
data.get('ids') 

어디 'JSON_OBJECT' Twitter API가 출력하는 JSON입니다. 'data'는 이제 json_object의 사전 표현입니다.

관련 문제