Monday, 15 July 2013

python - Django: Prevent string being unicode escaped? -


I am trying to stop the string in a post (in this case value variable) To avoid the request it is to be stored in JSON. My code is

  def addProduct (request): if request.POST: post = {} for the key in the request. POST: value = request 'Value' = json.loads (value) .encode ('utf-8') except for the POST [key] .encode ('utf-8 exception): pass {key] = value.encode (' utf-8 ') doc = Json.dumps (post)   

debugging I can see value type of Unicode which I believe is how Django manages objects request actual string Although Unicode does not get special characters, unless post [key] = value does not escape. If I change it to post [key] = value.encode ( 'Utf-8') to convert If I try, I get an error: 'ascii' can not decode codec byte 0xe2 position 38: no serial number (128)

Any ideas?

If you want to retain json.dumps special characters So I think that you can find the rational word sure_sc = false .

  1. Take a look at this answer:
  2. Instead of doing it by itself, Sunsh Chit_acci = incorrect I think the problem will be solved by avoiding the output json

    ex:

      json.dumps ({'H': u '\ xc2 \ xa3'},     

    Update: Compare [7] ]: For json.dumps ({'a': u '\ n) to be and and a unicode string: U00a3'}, make_acci = false] out [7]: In '[' a ']: "\ xa3"}' [8]: json.d Umps (['a': u '\ u00a3'}) outside [8]: '{"one": "\\ u00a3"} '

    Hope this helps!

No comments:

Post a Comment