【发布时间】:2020-03-17 07:10:21
【问题描述】:
我有以下格式的 JSON,我无法读取和加载 JSON 文件。出现额外数据错误。请帮忙
{"From":{"$type":"Microsoft.Bot.Schema.ChannelAccount, Microsoft.Bot.Schema","id":"e203b3e0-0b89- 11ea-b608-f5b0a8eb5137","name":"Bot","aadObjectId":null,"role":"bot"},"To":
{"$type":"Microsoft.Bot.Schema.ChannelAccount, Microsoft.Bot.Schema","id":"deb09575-8edb-411f-b875-418e7944a315","name":"User","aadObjectId":null,"role":"user"},"Text":""}
{"From":{"$type":"Microsoft.Bot.Schema.ChannelAccount, Microsoft.Bot.Schema","id":"e203b3e0-0b89-11ea-b608-f5b0a8eb5137","name":"Bot","aadObjectId":null,"role":"bot"},"To":
{"$type":"Microsoft.Bot.Schema.ChannelAccount, Microsoft.Bot.Schema","id":"a23f6775-c557-489d-996a-d6d3b329a234","name":"User","aadObjectId":null,"role":"user"},"Text":"Let me know if there’s anything else you need."}
{"From":{"$type":"Microsoft.Bot.Schema.ChannelAccount, Microsoft.Bot.Schema","id":"e203b3e0-0b89-11ea-b608-f5b0a8eb5137","name":"Bot","aadObjectId":null,"role":"bot"},"To":
{"$type":"Microsoft.Bot.Schema.ChannelAccount, Microsoft.Bot.Schema","id":"a9f3d513-e4d2-48dc-996a-df3c292e707c","name":"User","aadObjectId":null,"role":"user"},"Text":"I’m here if you need anything else."}
{"From":{"$type":"Microsoft.Bot.Schema.ChannelAccount, Microsoft.Bot.Schema","id":"e203b3e0-0b89-11ea-b608-f5b0a8eb5137","name":"Bot","aadObjectId":null,"role":"bot"},"To":
{"$type":"Microsoft.Bot.Schema.ChannelAccount, Microsoft.Bot.Schema","id":"b08c1237-82cb-4550-8b19-cef5a8e87439","name":"User","aadObjectId":null,"role":"user"},"Text":""}
{"From":{"$type":"Microsoft.Bot.Schema.ChannelAccount, Microsoft.Bot.Schema","id":"e203b3e0-0b89-11ea-b608-f5b0a8eb5137","name":"Bot","aadObjectId":null,"role":"bot"},"To":
{"$type":"Microsoft.Bot.Schema.ChannelAccount, Microsoft.Bot.Schema","id":"7eb76928-1a0e-4e31-80b2-519be0315d56","name":"User","aadObjectId":null,"role":"user"},"Text":""}
代码:
import json
import pandas as pd
from datetime import datetime
import dateutil.parser
##Date Format
date_format = "%Y-%m-%dT%H:%M:%S:%M"
#ft = 'C:/Users/abc/Desktop/xyz/pqr/aaa/Data5.json'
#data = json.dumps(ft)
#data = json.load(json.dumps(ft))
##Read the JSON file
with open('C:/Users/abc/Desktop/xyz/pqr/aaa/Data5.json',encoding= "utf-8") as f:
#data = json.loads(json.dumps([f]))
data = json.load(f)
错误
raise JSONDecodeError("Extra data", s, end)
JSONDecodeError: Extra data
【问题讨论】:
-
你显示的不是有效的 JSON
-
这些是一堆 JSON 对象,每个对象本身都是有效的 JSON。您可能需要将这些放在 JSON 数组中,用逗号分隔
-
data[340:360] ===> ',"Text":""}\n {"Fro'... 数据格式不对。应该有一个逗号分隔字典。
标签: python json python-3.x pandas dataframe