我正在使用Django-Smuggler将JSON数据上传到我的数据库.
当我加载JSON文件时,我收到错误: No JSON object could be decoded
我使用在线JSON验证器来确保数据是有效的.我通过执行数据转储获得了这些数据.
任何人都知道为什么会这样吗?
这是异常被提出(加星标)的地方:
try:
for format, stream in data:
objects = serializers.deserialize(format, stream)
for obj in objects:
model = obj.object.__class__
if router.allow_syncdb(using, model):
models.add(model)
counter += 1
obj.save(using=using)
if counter > 0:
sequence_sql = connection.ops.sequence_reset_sql(style, models)
if sequence_sql:
for line in sequence_sql:
cursor.execute(line)
**except Exception, e:**
transaction.rollback(using=using)
transaction.leave_transaction_management(using=using)
raise e
Run Code Online (Sandbox Code Playgroud)
这里是我的JSON文件的一般格式:
[
{
"pk": 1,
"model": "auth.message",
"fields": {
"message": "Successfully uploaded a new avatar.",
"user": 1
}
},
{
"pk": 2,
"model": "auth.message",
"fields": {
"message": "You have saved model 'mymodel'",
"user": 1
}
},
{
"pk": 3,
"model": "auth.message",
"fields": {
"message": "You have saved model 'sdfsd'",
"user": 1
}
},
{
"pk": 4,
"model": "auth.message",
"fields": {
"message": "Successfully uploaded a new avatar.",
"user": 1
}
},
{
"pk": 5,
"model": "auth.message",
"fields": {
"message": "Successfully updated your avatar.",
"user": 1
}
}
]
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9791 次 |
最近记录: |