我正在尝试读取JSON文件,但是由于出现错误,因此似乎无法正确处理,直到现在我尝试了其他方法均无效,我将在下面发布我当前的解决方案:
public class Example1 {
public static String readReddit()throws IOException, URISyntaxException {
JSONObject obj = new JSONObject("data/reddit/redditdumb.json");
JSONArray arr = obj.getJSONArray("data");
for (int i = 0; i < arr.length(); i++)
{
String kind = arr.getJSONObject(i).getString("kind");
.
.
.
}
return kind + ...;
}
}
这是我要读取的json文件:
[
{
"kind": "Listing",
"data": {
"modhash": "",
"children": [
{
"kind": "t3",
"data": {
"contest_mode": false,
"banned_by": null,
"media_embed": {},
"subreddit": "PoliticalDiscussion",
"selftext_html": "<!-- SC_OFF --><div class=\"md\"><p>The first Presidential Debate for the 2016 Elections will air tonight at 9:00PM Eastern at Hofstra University in New York. The debate will feature Donald Trump and Hillary Clinton in their first head-to-head televised debate. The debate will be 90 minutes and commercial free.</p>\n\n<p>The Debate is hosted by the Commission on Presidential Debates and will be moderated by NBC’s Lester Holt. Hillary Clinton will <a href=\"https://twitter.com/CBSNews/status/780506360257675264\">receive the first question</a>.</p>\n\n<hr/>\n\n<h2><strong>Where to Watch</strong></h2>\n\n<p>Unlike the primaries, these debates are hosted by the Commission on Presidential Debates and the broadcast is not restricted to one network, making for a wide range of viewing options. Here are just a few of the ways you can watch:</p>\n\n<p><strong>Television:</strong></p>\n\n<p>The event will be broadcast on most major TV channels, including ABC, CBS, CNN, C-SPAN, Fox News, MSNBC, and Univision.</p>\n\n<p><strong>Live Streams:</strong></p>\n\n<p><a href=\"https://www.c-span.org/2016presidentialDebates/\">C-SPAN</a></p>\n\n<p><a href=\"https://www.youtube.com/watch?v=L6QElWIKfDk\">Washington Post (YouTube)</a></p>\n\n<p><a href=\"https://www.youtube.com/watch?v=EuHuzhzb1nc\">PBS (YouTube)</a></p>\n\n<p><a href=\"https://www.youtube.com/watch?v=855Am6ovK7s\">NBC (YouTube)</a></p>\n\n<p><a href=\"https://twitter.com/i/live/778347749217406976\">Bloomberg Politics (Twitter with real-time fact checking)</a></p>\n\n<p><a href=\"https://www.facebook.com/ABCNews/\">ABC (Facebook)</a></p>\n\n<hr/>\n\n<h2><strong>Live Discussion</strong></h2>\n\n<p>If you&#39;d like to participate in real-time discussion, we encourage you to head over to <a href=\"https://discord.gg/caAhhCv\">our Discord server</a> and check out our <a href=\"https://discordapp.com/channels/154635757615710208/229738984618721280\">Presidential Debate Channel</a>. </p>\n\n<hr/>\n\n<p>Please use this thread to discuss your tonight&#39;s debate as it happens. All subreddit rules still apply in live threads and in Discord, so please remember to remain civil and try to keep discussion quality high. <strong>This thread will be closely watched, and any rule violations are certain to be met with heavy-handed moderation. Be nice!</strong></p>\n</div><!-- SC_ON -->",
"selftext": "The first Presidential Debate for the 2016 Elections will air tonight at 9:00PM Eastern at Hofstra University in New York. The debate will feature Donald Trump and Hillary Clinton in their first head-to-head televised debate. The debate will be 90 minutes and commercial free.\n\nThe Debate is hosted by the Commission on Presidential Debates and will be moderated by NBC’s Lester Holt. Hillary Clinton will [receive the first question](https://twitter.com/CBSNews/status/780506360257675264).\n\n-----\n\n**Where to Watch**\n-\n\nUnlike the primaries, these debates are hosted by the Commission on Presidential Debates and the broadcast is not restricted to one network, making for a wide range of viewing options. Here are just a few of the ways you can watch:\n\n**Television:**\n\nThe event will be broadcast on most major TV channels, including ABC, CBS, CNN, C-SPAN, Fox News, MSNBC, and Univision.\n\n**Live Streams:**\n\n[C-SPAN](https://www.c-span.org/2016presidentialDebates/)\n\n[Washington Post (YouTube)](https://www.youtube.com/watch?v=L6QElWIKfDk)\n\n[PBS (YouTube)](https://www.youtube.com/watch?v=EuHuzhzb1nc)\n\n[NBC (YouTube)](https://www.youtube.com/watch?v=855Am6ovK7s)\n\n[Bloomberg Politics (Twitter with real-time fact checking)](https://twitter.com/i/live/778347749217406976)\n\n[ABC (Facebook)](https://www.facebook.com/ABCNews/)\n\n------\n\n**Live Discussion**\n-\n\nIf you'd like to participate in real-time discussion, we encourage you to head over to [our Discord server](https://discord.gg/caAhhCv) and check out our [Presidential Debate Channel](https://discordapp.com/channels/154635757615710208/229738984618721280). \n\n----------\n\nPlease use this thread to discuss your tonight's debate as it happens. All subreddit rules still apply in live threads and in Discord, so please remember to remain civil and try to keep discussion quality high. **This thread will be closely watched, and any rule violations are certain to be met with heavy-handed moderation. Be nice!**",
"likes": null,
"suggested_sort": "new",
"user_reports": [],
"secure_media": null,
"saved": false,
"id": "54nuut",
"gilded": 0,
"secure_media_embed": {},
"clicked": false,
"report_reasons": null,
"author": "BagOnuts",
"media": null,
"score": 550,
"approved_by": null,
"over_18": false,
"domain": "self.PoliticalDiscussion",
"hidden": false,
"num_comments": 8576,
"thumbnail": "",
"subreddit_id": "t5_2sfmf",
"edited": 1474937730,
"link_flair_css_class": "green2",
"author_flair_css_class": "",
"downs": 0,
"archived": false,
"removal_reason": null,
"stickied": false,
"is_self": true,
"hide_score": false,
"permalink": "/r/PoliticalDiscussion/comments/54nuut/debate_megathread_live_discussion_thread_for_the/",
"locked": false,
"name": "t3_54nuut",
"created": 1474964458,
"url": "https://www.reddit.com/r/PoliticalDiscussion/comments/54nuut/debate_megathread_live_discussion_thread_for_the/",
"author_flair_text": "Extra Nutty",
"quarantine": false,
"title": "[Debate Megathread] LIVE Discussion Thread for the First Presidential Debate of 2016",
"created_utc": 1474935658,
"link_flair_text": "Presidential Debate",
"ups": 550,
"upvote_ratio": 0.83,
"mod_reports": [],
"visited": false,
"num_reports": null,
"distinguished": null
}
}
],
"after": null,
"before": null
}
},
{
"kind": "Listing",
"data": {
"modhash": "",
"children": [
{
"kind": "t1",
"data": {
"subreddit_id": "t5_2sfmf",
我遇到的错误是我似乎无法真正找到解决方案:
Exception in thread "main" org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]
。任何帮助将不胜感激!