代码之家  ›  专栏  ›  技术社区  ›  STORM

手动生成的JSON可以工作,但通过JSON.dumps创建的JSON不工作,即使输出看起来完全相同

  •  0
  • STORM  · 技术社区  · 6 年前

    我正在使用 Marketo marketo-rest-python . 我可以创建潜在客户,也可以通过以下基本代码对其进行更新:

    leads = [{"email":"joe@example.com","firstName":"Joe"},{"email":"jill@example.com","firstName":"Jill"}]
    lead = mc.execute(method='create_update_leads', leads=leads, action='createOnly', lookupField='email', 
                    asyncProcessing='false', partitionName='Default')
    

    leads = []
    
    lead = {}
    lead['email'] = "joe@example.com"
    lead['firstName'] = "Joe"
    leads.append(lead)
    
    lead = {}
    lead['email'] = "jill@example.com"
    lead['firstName'] = "Jill"
    leads.append(lead)
    
    json_leads = json.dumps(leads, separators=(',', ':'))
    
    print(json_leads)
    

    那么在微软Azure数据库中的输出是完全相同的,但是Marketo系统返回一个 609 ->无效的JSON。

    [{"email":"joe@example.com","firstName":"Joe"},{"email":"jill@example.com","firstName":"Jill"}]
    

    与样品完全相同。当我使用示例JSON代码行时,它起作用,但我自己生成的JSON不起作用。

    有人知道这会是什么吗?我在微软Azure数据库中使用Python。

    1 回复  |  直到 6 年前
        1
  •  0
  •   madprogrammer    6 年前

    我相信你不需要打电话 json.dumps ,就这样做吧

    leads = []
    
    lead = {}
    lead['email'] = "joe@example.com"
    lead['firstName'] = "Joe"
    leads.append(lead)
    
    lead = {}
    lead['email'] = "jill@example.com"
    lead['firstName'] = "Jill"
    leads.append(lead)
    
    lead = mc.execute(method='create_update_leads', leads=leads, action='createOnly', 
    lookupField='email', asyncProcessing='false', partitionName='Default')