标题说得最多:
我将 JSON 存储在 DataStore 中。所有 json 都被转换为 html 实体,我该如何避免这种情况?
原来我有
myJson = db.StringProperty()
它抱怨我的 json 太长,而 StringProperty 的限制约为 500 个字符。建议改用 TextProperty。
它插入没有问题,但是当我从数据库中获取它时,现在 myJson 看起来像这样:
{ "timeUnit": "14", "taskCounter": "0", "dependencyCounter": "0", "tasks": [], "dependencies": []}
有什么建议吗?
编辑:
代码:
模型:
the_json = db.TextProperty()
保存:
myObjectKey = request.POST["myKey"]
myJson = request.POST["myJson"]
element = myObject.get(myObjectkey)
logging.error(" -------------------------")
element.the_json = myJson
element.put()
加载:
params = {}
myObjectKey = request.POST["myKey"]
element = myObject.get(myObjectKey)
params['the_json'] = myObject.the_json
return respond(request, "ajax/load.html",params) #this function is a redirect to shortcuts.render_to_response
对于 ajax,我使用 jquery 来处理所有事情。JSON 是一个没有 '\n' 的普通字符串。:
json_in_the_js = '{ "timeUnit": ...';