![](/img/trans.png)
[英]python json.dumps and json.loads before DynamoDB insertion
[英]JSON viewers don't accept my pattern even after dict going through json.dumps() + json.loads()
在a = json.dumps(dicter)
和print(json.loads(a))
之后打印的結果是這樣的:
{
'10432981': {
'tournament': {
'name': 'Club Friendly Games',
'slug': 'club-friendly-games',
'category': {
'name': 'World',
'slug': 'world',
'sport': {
'name': 'Football',
'slug': 'football',
'id': 1
},
'id': 1468,
'flag': 'international'
},
'uniqueTournament': {
'name': 'Club Friendly Games',
'slug': 'club-friendly-games',
'category': {
'name': 'World',
'slug': 'world',
'sport': {
'name': 'Football',
'slug': 'football',
'id': 1
},
'id': 1468,
'flag': 'international'
},
'userCount': 0,
'hasPositionGraph': False,
'id': 853,
'hasEventPlayerStatistics': False,
'displayInverseHomeAwayTeams': False
},
'priority': 0,
'id': 86
}
}
}
但是當嘗試在任何 json 查看器中讀取時,他們會警告格式不正確,但沒有指定問題出在哪里。
如果在將 dict 轉換為 JSON 時甚至在讀取它時都沒有產生任何錯誤,為什么視圖會警告失敗?
您必須使用雙引號 (") 將字符串括起來。json.loads 返回一個 python 字典,因此它不是有效的 JSON 對象。如果您想獲取有效的 JSON,您可以獲取 json.dumps 返回的字符串。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.