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

Java 将包含内部json twitter4j数据的文件解析为纯文本,java,json,twitter4j,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#innovatio

我有一个包含数据的文件(从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
}
UserJSONImpl{
id=182857317,
name='Inria',
屏幕名称='Inria',
地点:'法国',
description='Institutederechercheensciencedu#numérique,
设计工程师、信息、数学、创新[
compteofficiel
]',
isContributorsEnabled=false,
profileImageUrl=“”,
profileImageUrlHttps='',
url=“”,
isProtected=false,
followersCount=10171,
status=StatusJSONImpl{
createdAt=Monoc2118:56:17CEST2013,
id=3923335283588704,
text='RT@upmc:Y'a-t-ilunpilotedansl'avion?口语18havecGillesDowek@Inria',
来源=“”,
isTruncated=false,
inReplyToStatusId=-1,
inReplyToUserId=-1,
isFavorited=false,
在replytoscreenname='null'中,
地理位置=空,
place=null,
retweetCount=3,
isPossiblySensitive=false,
捐款人ID=[
J@3cbd7173,
RetweetdStatus=null,
用户实体=[
用户提及实体JSONIMPL{
name='UPMC-Paris',
screenName='upmc',
id=19063270
},
用户提及实体JSONIMPL{
name='Inria',
屏幕名称='Inria',
id=182857317
}
],
URL实体=[
URLEntityJSONImpl{
url=“”,
expandedURL='',
显示URL=“”
}
],
哈希标记实体=[
HashtagEntityJSONImpl{
text='informatique'
}
],
媒体实体=[
],
currentUserRetweetId=-1,
用户=null
},
profileBackgroundColor='FFFFFF',
profileTextColor='3434',
profileLinkColor='AAAAA',
profileSidebarFillColor='BDBDBD',
profileSidebarBorderColor='FFFFFF',
profileUseBackgroundImage=true,
showAllInlineMedia=false,
friendsCount=1209,
createdAt=WedAug2517:30:06CEST2010,
FavoriteSCount=927,
utcOffset=7200,
时区“=”巴黎“,
profileBackgroundImageUrl='',
profileBackgroundImageUrlHttps='',
profileBackgroundTiled=false,
lang='fr',
statusesCount=2783,
isGeoEnabled=false,
isVerified=false,
translator=false,
listedCount=544,
isFollowRequestSent=false
}
我想将此数据格式转换为包含所有字段的纯文本格式


感谢您的帮助

有几个用于JSON处理的API。
新的JSR-353(JEE7的一部分)可能对你有用,你可以试试 仅举两例。
两者都主要迭代完整的JSON对象,该对象可以由JSON字符串构造。
那么如何格式化文本呢?
如果您只想将所有内容放入文本文件中,您可以将其附加到主类的字符串成员中,
如果您想生成csv文本文件
您正在一个数据模型的两个不同视图之间进行转换
,在创建csv文件的视图(实际的csv文件)之前,应该为csv文件构建一个适当的数据模型。

我确实看过JSON API,但据我所知,它不是JSON格式。它是twitter4J转储(twitter4J-UserJSONImpl中称为实体)。我想先将其转换为正确的Json格式,然后解析Json文件以递归方式读取其对象。请原谅。是的,你是对的,这不是有效的Json。这种转换通常由正则表达式完成,但并不太容易。你需要一个Twitter格式的解析器来读取字符串和例如,isTruncated=false,所以JSON应该是isTruncated:false,但是你不能简单地用“=”代替“:”,因为等号可以是文本的一部分,尽管我不明白Twitter4J为什么不使用JSON。这看起来像是一个
toString
r对象的E表示,如果您可以在接收结果时以您需要的格式编写它,则会更好。虽然我猜这在这里不可能,因为您已经积累了数据?是的,这是不可能的,而且数据的大小非常大。这就是为什么我正在寻找更改它的解决方案。现在,我正在解析字符串to获取JSON格式。如有任何进一步建议,我们将不胜感激。