将内部json twitter4j数据的文件解析为纯文本

时间:2013-12-20 09:42:07

标签: java json twitter4j

我有一个包含数据的文件(从Twitter4J方法获得,如twitter.showUser()),每行都看起来像

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='RT@upmc: Y'a-t-ilunpilotedansl'avion?Colloquiumd'#informatiquedemainsoirà18havecGillesDowek@Inria',
    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=[
        J@3cbd7173,
        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
}

我想将此数据格式转换为纯文本格式包含所有字段。

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

有几个用于JSON处理的API。
新的JSR-353(JEE 7的一部分)可能对您有用,您可以试试http://www.jdom.org/ 仅提两个。
两者都主要遍历完整的JSON - 可以从JSON - String构造的对象 那么如何设置文本格式呢?
如果你只想将所有内容放入一个文本文件中,你可以附加到Main类的String成员,如果你想生成一个csv -text -file 您正在数据模型的两个不同视图之间进行转换,并且应该在创建csv文件的视图之前为csv文件构建正确的数据模型,即实际的csv文件。