OAuthConnection类型的对象不可JSON序列化

问题描述 投票:0回答:1

我正在通过以下代码使用bigcommerce API检索产品

def get_bigcommerce_products(request):
    a = api.Products.all()
    return json.dumps(a)

我需要JSON响应。所以我用了json.dumps。但这给了我以下错误'OAuthConnection类型的对象不可JSON序列化'。我试图将其转换为字典,但无法正常工作。

所以请帮助我。我正在使用Python 3.7和Django 2.2。

javascript python django bigcommerce
1个回答
0
投票

您需要手动序列化列表中的对象。没有json模块可以为您执行字段遍历。示例代码将是:

   l_products =[] 
   for obj in Product.objects.all():
      l_dictObj ={}
      l_dictObj['some_field'] = obj.some_variable
      #...more fields here
      l_products.append(l_dictObj)
© www.soinside.com 2019 - 2024. All rights reserved.