[Python3]正确重新格式化JSON

2024-06-16 14:12:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在抓取一个包含请求和BS4的网站,我提取了以下JSON(如果你可以这么称呼它的话)。问题是它的格式不正确:

{'event':'productClick', 'userId': null,
  'portalId': null,
  'cookieId': null,
  'customerId': null,
  'customerType': null,
  'sessionId': null,
  'displayMode': null,
  'userAgent': null,
  'language_Iso639_1Code': null,
  'userAgentIsMobile': null,
  'user': null,
  'ecommerce': {
    'click': {
      'actionField': {
        'list': 'Produktdetails Varianten',
        'id': null
      },
      'products': [
        {
          'id': '5714877',
          'name': 'G-Series G610 Orion Brown',
          'price': '139.0000',
          'brand': 'Logitech',
          'category': 'Tastatur',
          'variant': 'USB, CH, Kabel, MX-Brown',
          'gx_nameWithBrand': 'Logitech G-Series G610 Orion Brown',
          'gx_brandId': 292,
          'gx_productTypeId': 55,
          'gx_priceExcl': 'CHF 128.70',
          'gx_isSalesPromotion': false,
          'gx_isShownInShowRoom': false,
          'gx_rating': 4.5,
          'gx_productGroup1': 389,
          'gx_productGroup2': 254
        }
      ]
    }
  }}

有什么方法可以把JSON格式化成JSON标准吗


Tags: eventidjsonfalse网站格式nullseries