簡體   English   中英

即使在 dict 通過 json.dumps() + json.loads() 之后,JSON 查看器也不接受我的模式

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM