我正在使用Django-Smuggler將JSON數據上傳到我的數據庫。我收到錯誤沒有JSON對象可以被解碼,但有一個有效的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
而且,這裏是我的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
}
}
]
向我們展示一些代碼,看看會發生什麼 –
沒有至少您使用的輸入和輸出,我們不能告訴你很多。另外,你真的在問一個關於使用GUI工具進行JSON解析和數據庫更新的問題,我想這不完全是StackExchange的問題。也許超級用戶或什麼? –
這並沒有告訴我們任何新東西,真的。顯然,Python中的JSON解析器認爲你的JSON字符串有問題。無法看到JSON,很難說出什麼。 –