2013-12-20 62 views
0

我有包含數據(如從Twitter4J方法如twitter.showUser()中獲得)的文件,並且每個線的樣子解析與內部JSON twitter4j數據的文件爲純文本

UserJSONImpl{ 
id=182857317, 
name='Inria', 
screenName='Inria', 
location='France', 
description='Institutderechercheensciencesdu#numérique, 
ducôtédesinventeurs#informatique#mathématiques#innovation[ 
    compteofficiel 
]', 
isContributorsEnabled=false, 
profileImageUrl='', 
profileImageUrlHttps='', 
url='', 
isProtected=false, 
followersCount=10171, 
status=StatusJSONImpl{ 
    createdAt=MonOct2118: 56: 17CEST2013, 
    id=392333528358088704, 
    text='[email protected]: Y'a-t-ilunpilotedansl'avion?Colloquiumd'#informatiquedemainsoirà[email protected]', 
    source='<ahref=""rel="nofollow">TweetDeck</a>', 
    isTruncated=false, 
    inReplyToStatusId=-1, 
    inReplyToUserId=-1, 
    isFavorited=false, 
    inReplyToScreenName='null', 
    geoLocation=null, 
    place=null, 
    retweetCount=3, 
    isPossiblySensitive=false, 
    contributorsIDs=[ 
     [email protected], 
     retweetedStatus=null, 
     userMentionEntities=[ 
      UserMentionEntityJSONImpl{ 
       name='UPMC-Paris', 
       screenName='upmc', 
       id=19063270 
      }, 
      UserMentionEntityJSONImpl{ 
       name='Inria', 
       screenName='Inria', 
       id=182857317 
      } 
     ], 
     urlEntities=[ 
      URLEntityJSONImpl{ 
       url='', 
       expandedURL='', 
       displayURL='' 
      } 
     ], 
     hashtagEntities=[ 
      HashtagEntityJSONImpl{ 
       text='informatique' 
      } 
     ], 
     mediaEntities=[ 

     ], 
     currentUserRetweetId=-1, 
     user=null 
    }, 
    profileBackgroundColor='FFFFFF', 
    profileTextColor='343434', 
    profileLinkColor='AAAAAA', 
    profileSidebarFillColor='BDBDBD', 
    profileSidebarBorderColor='FFFFFF', 
    profileUseBackgroundImage=true, 
    showAllInlineMedia=false, 
    friendsCount=1209, 
    createdAt=WedAug2517: 30: 06CEST2010, 
    favouritesCount=927, 
    utcOffset=7200, 
    timeZone='Paris', 
    profileBackgroundImageUrl='', 
    profileBackgroundImageUrlHttps='', 
    profileBackgroundTiled=false, 
    lang='fr', 
    statusesCount=2783, 
    isGeoEnabled=false, 
    isVerified=false, 
    translator=false, 
    listedCount=544, 
    isFollowRequestSent=false 
} 

我會如這種數據格式轉換爲純文本格式的所有字段。

感謝您的幫助

+0

這看起來像是對象的'toString'表示,如果您可以在接收結果時以需要的格式編寫它,那將會更好。雖然我猜這在這裏是不可能的,因爲你已經積累了數據? – Jonathan

+0

是的,這是不可能的,而且數據的大小也是非常巨大的。這就是爲什麼我正在尋找解決方案來改變它。現在,我正在解析字符串以獲取JSON格式。任何進一步的建議,讚賞。 – user156379

回答

0

有幾個API的周圍JSON - 處理。
新的JSR-353(JEE 7的一部分)可能對你有用,你可以嘗試http://www.jdom.org/ 只是提到兩個。
兩者都主要遍歷完整的JSON - 可以從JSON - String構造的對象。
那麼如何設置文本的格式呢?
如果您只是想將所有內容放入文本文件中,您可以將其追加到主要類的字符串成員
如果要生成csv文本文件 您正在數據模型的兩個不同視圖之間進行轉換
,並且應該在創建它的視圖(實際的csv文件)之前爲csv文件構建適當的數據模型。

+0

我的確看過JSON API,但據我瞭解,它不是JSON格式。它是一個twitter4J轉儲(在twitter4J中調用的實體 - UserJSONImpl)。我想將它轉換爲首先適當的Json格式,然後解析json文件以遞歸地從其對象讀取。 – user156379

+0

請原諒我。是的,你是對的,這是不合法的JSON。 – Peter

+0

請原諒我。是的,你是對的,這是不合法的JSON。那麼,這種轉換通常是由正則表達式完成的,儘管它並不太容易。您將需要一個Twitter - 格式的解析器,它可以讀取字符串,然後將其轉換,無論它可以直接轉換爲文本格式還是轉換爲JSON。以例如isTruncated = false,所以JSON將被截斷:false,但是你不能簡單地用'='代替':',因爲等號可能是文本文本的一部分,儘管我不明白爲什麼Twitter4J不會不使用JSON。 – Peter