开发者

GQL: I'm storing JSON in the DataStore. All json is getting converted to html entities, how to avoid this?

开发者 https://www.devze.com 2022-12-26 17:17 出处:网络
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?

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 :)

0

精彩评论

暂无评论...
验证码 换一张
取 消