将JSON数组转换为JSON对象(Python)
我有一个空的JSON数组将JSON数组转换为JSON对象(Python),python,json,Python,Json,我有一个空的JSON数组 FINAL\u ELOGII\u DATA\u ARRAY=[] 在Python对象的for循环中通过.append填充的 for ord in FINAL_SHOPIFY_DATA: FINAL_ELOGII_DATA_ARRAY.append({ "date": int(ELOGII_TODAY), "customer": str(ord.id), "tasks": [ {
FINAL\u ELOGII\u DATA\u ARRAY=[]
在Python对象的for循环中通过.append填充的
for ord in FINAL_SHOPIFY_DATA:
FINAL_ELOGII_DATA_ARRAY.append({
"date": int(ELOGII_TODAY),
"customer": str(ord.id),
"tasks": [
{
"date": int(0),
"customer": str(ord.id),
"type": int(0),
"location": {
"address": str(ord.shipping_address.address1),
"postCode": str(ord.shipping_address.zip),
"city": str(ord.shipping_address.city),
"country": str(ord.shipping_address.country),
"contactName": str(ord.customer.first_name) + ' ' + str(ord.customer.last_name),
"contactPhone": str(ord.shipping_address.phone),
"contactEmail": str(ord.email),
"ref": str(ord.customer.first_name) + ' ' + str(ord.customer.last_name)
}
}
]
})
并输出以下内容(示例):
因此JSON数组被正确填充,但是,我需要它是一个JSON对象,而不是一个数组,因为我发布到的API不支持数组,只支持对象。关于将其转换为对象的任何提示?
对象=数组[0]
?@l3via如果我在数组中只有第一个结果,当我有多个时,我将如何获得其余的?我有一个空的JSON数组。。。对我来说,这看起来像是一个简单的Python列表。请提供一个,以及预期的输出。谢谢@Suriya-我已经通过上面的“FINAL_ELOGII_DATA_array.append({)”将数组追加到一个数组中。我需要将该数组转换为一个对象列表,没有包装的括号[]。数据内容的长度是1吗?
class Container():
def __init__(self, listData):
self.listData = listData
for..
listToSend.append(data)
container = Container(listToSend)
class Container():
def __init__(self, listData):
self.listData = listData
for..
listToSend.append(data)
container = Container(listToSend)