GQL: I'm storing JSON in the DataStore. All json is getting converted to html entities, how to avoid this?
The tittle says most:
I'm stor开发者_如何学JAVAing JSON in the DataStore. All json is getting converted to html entities, how can I avoid this?
Original I had
myJson = db.StringProperty()
it complained the json i had was to long and StringProperty had a limit of around 500 chars. Sugesting to use TextProperty instead.
It inserted without problems but now myJson looks like this when i fetch it from the database:
{ "timeUnit": "14", "taskCounter": "0", "dependencyCounter": "0", "tasks": [], "dependencies": []}
Any sugestions?
Edit:
Code:
Model:
the_json = db.TextProperty()
Saving:
myObjectKey = request.POST["myKey"]
myJson = request.POST["myJson"]
element = myObject.get(myObjectkey)
logging.error(" -------------------------")
element.the_json = myJson
element.put()
Loading:
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
For ajax I'm using jquery to handle everything. The JSON is a normal string with no '\n' in it.:
json_in_the_js = '{ "timeUnit": ...';
How are you fetching and displaying the JSON? This definitely isn't an issue with how it's stored in the datastore, but rather with how it's displayed, or possibly how it's being recieved. We need to be able to see all the code that handles it to tell which.
The problem wasn't in the datastore. It was in the fact that I was using a template to write the JSON in.
I generated the response by hand with:
response = HttpResponse(myObject.the_json)
And it worked great :)
精彩评论