从 json 推文中获取 json 用户

编程入门 行业动态 更新时间:2024-10-28 19:35:39
本文介绍了从 json 推文中获取 json 用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一条已存储在文件中的推文.我想将用户提取为 json 对象并将其存储在不同的文件中.java.lang.IllegalStateException 中的以下结果:显然 jsonStoreEnabled 未设置为 true.

I have a tweet that I had stored in a file. I want to extract the user as a json object and store it in a different file. The following results in java.lang.IllegalStateException: Apparently jsonStoreEnabled is not set to true.

String jsonStatus; //Content read from a file
Status status = TwitterObjectFactory.createStatus(jsonStatus); //no problem here
String jsonUser = TwitterObjectFactory.getRawJSON(status.getUser()); //Exception

如何将 jsonStoreEnabled 设置为 true?或者,还有其他方法吗?我不必坚持使用 Twitter4j 来创建 jsonUser.我尝试了 json-simple,但结果字符串无法用 Twitter4j 解析.

How can I set jsonStoreEnabled to true? Or, is there another way of doing it? I don't have to stick with Twitter4j to create jsonUser. I tried json-simple, but the resulting String is not parsable with Twitter4j.

推荐答案

事实证明 org.json 包在这种情况下很有帮助:

It turns out that the org.json package was helpful in this case:

public static String extractUser(String rawJSON) {
    return new org.json.JSONObject(rawJSON).get("user").toString();
}

这篇关于从 json 推文中获取 json 用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-29 15:26:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1192039.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文中   用户   json

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!