我使用initial_data.json将初始数据加载到某些模型。 在我的一个模型中,我想存储json数据。 现在我的问题是,如果我尝试将json数据加载到我的模型,它将给出syntex错误。
例如。,
{ "pk": "16443630-d2c5-11e4-8b84-00000000000b", "fields": { "fk_fact_type": "6a545d1c-cbca-11e4-a17e-000000000007", "content":"{"data": "dummy data"}" }, "model": "model name" },当我从json文件和"content":"{"data": "dummy data"}"加载数据时,这个内容会明显产生语法错误"content":"{"data": "dummy data"}"不是有效的json。 如果我尝试将数据加载为{'data': 'dummy data'}那么它就不是一个有效的json。
任何解决方案如何从json文件加载json字段的初始数据?
I am loading initial data to some models using initial_data.json . In one of my model I want to store json data . Now my problem is if I try load json data to my model it will give syntex error .
e.g .,
{ "pk": "16443630-d2c5-11e4-8b84-00000000000b", "fields": { "fk_fact_type": "6a545d1c-cbca-11e4-a17e-000000000007", "content":"{"data": "dummy data"}" }, "model": "model name" },this content will obvious generate syntax error as I am loading data from json file and "content":"{"data": "dummy data"}" is not a valid json. If I'll try to load data as {'data': 'dummy data'} then it is not a valid json .
Any solution how to load initial data for json field from json file ?
最满意答案
删除content字典周围不需要的双引号:
"content": {"data": "dummy data"}Remove unneeded double quotes around content dictionary:
"content": {"data": "dummy data"}更多推荐
发布评论