【发布时间】:2023-01-02 20:32:01
【问题描述】:
我必须编写一个 Jupyter Notebook 来对 Profile 类别中的问答线程进行分析。要分析的数据包含在 JSON 文件中。这个文件非常大,其中包含不止一个讨论。当我导入文件并尝试在终端中可视化它时,我看到了这个错误:
JSONDecodeError: Extra data: line 855 column 1 (char 26418)
分析导入的文件,我注意到第 855 行对应于讨论的结束和下一个讨论的开始。
在我正在谈论的 json 文件的一部分之后。
{
"Title": "How to get a new badge?",
"Number": "18294",
"Category": "Profile",
"Author": "deeperwhales",
"Date": "2022-06-10T18:42:30Z",
"State": "Answered",
"Answered_by": "wavescats",
"Body": "How to get a new badge?",
"Upvotes": 140,
"Labels": [
"Profile"
],
"Participants": 31,
"Answer_count": 80,
"Reply_count": 502,
"Answers": [
{
"IsOffTopic": false,
"Author": "wavescats",
"Date": "2022-06-10T18:43:14Z",
"Body": "After answering two discussions, You will get Galaxy Brain badge More details here: https://github.com/Schweinepriester/github-profile-achievements",
"Upvotes": 59,
"Accepted": true,
"Reply_count": 239,
"Replies": [
{
"Author": "pajeeh",
"Body": "Use the most number of languages.",
"Date": "2022-10-08T09:06:56Z",
"IsAuthor": false,
"Sentiment": "neutral"
},
{
"Author": "Khairul989",
"Body": "thanks",
"Date": "2022-10-09T16:05:54Z",
"IsAuthor": false,
"Sentiment": "positive"
},
{
"Author": "ibrahimmemonn",
"Body": "Thanks",
"Date": "2022-10-18T10:10:48Z",
"IsAuthor": false,
"Sentiment": "positive"
}
],
"Sentiment": "positive"
},
{
"IsOffTopic": false,
"Author": "akbar-ardiansyah",
"Date": "2022-06-10T19:44:45Z",
"Body": "pull shrark was opened when you opened pull requests that have been merged.",
"Upvotes": 6,
"Accepted": false,
"Reply_count": 16,
"Replies": [
{
"Author": "deividepaulino1",
"Body": "thanks",
"Date": "2022-07-08T19:33:35Z",
"IsAuthor": false,
"Sentiment": "positive"
},
{
"Author": "darkhorse-coder",
"Body": "Exactly, if you approach 100+ pr merged, you will get Silver Pull Shark. ;)",
"Date": "2022-07-20T16:55:13Z",
"IsAuthor": false,
"Sentiment": "neutral"
},
{
"Author": "Splayfery",
"Body": "How can I get different levels of this achievment?",
"Date": "2022-07-20T18:24:17Z",
"IsAuthor": false,
"Sentiment": "neutral"
},
{
"Author": "wizardigor",
"Body": "Quais outros emblemas est\u00e3o disponiveis?",
"Date": "2022-08-25T13:08:52Z",
"IsAuthor": false,
"Sentiment": "neutral"
},
{
"Author": "burhancan-stack",
"Body": "thanks.",
"Date": "2022-09-20T12:09:56Z",
"IsAuthor": false,
"Sentiment": "positive"
}
],
"Sentiment": "neutral"
}
],
"Sentiment": "neutral"
} ********************************Line 855*********************************
{
"Title": "feed back on achievement badges",
"Number": "21073",
"Category": "Profile",
"Author": "SteveALee",
"Date": "2022-07-22T13:51:48Z",
"State": "Unanswered",
"Answered_by": null,
"Body": "Please turn these off by default. Gamification has no place here. Useless twaddle.",
"Upvotes": 32,
"Labels": [
"Profile"
],
"Participants": 13,
"Answer_count": 13,
"Reply_count": 10,
"Answers": [
{
"IsOffTopic": false,
"Author": "jgmac1106",
"Date": "2022-07-22T16:04:07Z",
"Body": "i agree on off by default. Always default to privacy. I disagree on utility. If the achievements had useful metadata that complied with current industry recommendations the information could be ingested to track role based training requirements of developers, aid in portfolio reviews, and allow users to control their learning data outside of employers. Granted the achievements (little disappointing) are just images for now, but it could be easily extendable to allow parsing, ignestiong, and recording in an immutable ledger.",
"Upvotes": 3,
"Accepted": false,
"Reply_count": 2,
"Replies": [
{
"Author": "SteveALee",
"Body": "That's an interesting idea but a big \"if\" to get the badges representing meaningful development metrics rather than feel good.",
"Date": "2022-07-22T16:18:47Z",
"IsAuthor": true,
"Sentiment": "positive"
},
{
"Author": "seek-dev",
"Body": "Gamifying something just to sell more metadata to corporations who parasitize human privacy is inherently exploitation. The purpose is to manifest addictive behaviour with immaterial rewards. Which is a manipulative function of industrial psychology, though common practice in today's ecosystems of consumer spyware and vacuous social media.",
"Date": "{{datetime}}",
"IsAuthor": false,
"Sentiment": "negative"
}
],
"Sentiment": "negative"
},
{
"IsOffTopic": false,
"Author": "MrSarno",
"Date": "2022-07-22T16:50:03Z",
"Body": "I'm not sure whether you're aware, but there is a setting to disable them here. I don't feel strongly about your suggestion one way or the other. I think people are more likely to check for settings to disable features they dislike than they are to search for features they might hypothetially like and wish to enable. In addition, some people may not think to look for settings, and so there would likely be a significant number of people reporting the lack of achievements as a bug, and / or creating discussions to ask why they don't appear to be working. At least the setting's there for those who want it.",
"Upvotes": 13,
"Accepted": false,
"Reply_count": 2,
"Replies": [
{
"Author": "MlgmXyysd",
"Body": "I agree with this point",
"Date": "2022-07-24T17:37:27Z",
"IsAuthor": false,
"Sentiment": "neutral"
},
{
"Author": "mark-i-m",
"Body": "Thanks for this! I would never have found that setting on my own.",
"Date": "2022-07-25T17:49:57Z",
"IsAuthor": false,
"Sentiment": "neutral"
}
],
"Sentiment": "neutral"
}
这是我写的代码
import json
file_json = open("/content/drive/MyDrive/Lab_SC/gh_discussions_badges.json")
data = json.load(file_json)
print (data)
这是错误
JSONDecodeError: Extra data: line 855 column 1 (char 26418)
【问题讨论】:
-
也许您的文件不是真正的
json。你能删除所有从 855 开始的行吗? -
问题是您有多个 {} 但它们不在列表/数组中。您可以将文件作为文本文件打开并编辑文件以在文件开头添加 [,在末尾添加 ],并在两个元素之间添加一个逗号(例如,将“} \n {”替换为“},\ n {")
标签: python json import sentiment-analysis