Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9001405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:25:54+00:00 2026-06-16T00:25:54+00:00

I’m building a json web service which contains strings with characters like é,ñ,Á,etc. Using

  • 0

I’m building a json web service which contains strings with characters like é,ñ,Á,etc.

Using python I found this snippet of code that works perfectly when I run it in console:

import json
string = "NIÑO, ÁRBOL, HÉROE"
print json_dumps({'string': string}, ensure_ascii=False, encoding='utf-8')

The thing is that I’m using Django, and it doesn’t look like it is as straightforward as the code above. Here’s a peek of what I’m doing at my views.py file

import json
from models import *
from django.http import HttpResponse
from django.db.models import Q

def jsonService(request):
    # The following line performs a query at the db
    myObjects = MyObjects.objects().filter( Q(...) ) 

    result = {"string": myObject[0].field } # let's say myObject[0].field contains "NIÑO, ÁRBOL, HÉROE"

    # Prepares a response
    response = HttpResponse(json.dumps(result, ensure_ascii=False, encoding="utf-8"))
    # Sets the heades of content type and its charset
    response['Content-type'] = 'application/json; charset=utf-8'

    # Returns the response we prepared
    return response

The output of this code is:

{ 
    string : "NIôO, ÃRBOL, HÃ%ROE"
}

if I apply python’s function repr() to the string myObject[0].field when I assemble the result object, to my surprise the result is:

{ 
    string : "NI\xc3\u2018O, \xc3\x81RBOL, H\xc3\u2030ROE"
}

What I can infere from here is that maybe the strings that the db delivers (which are unicode strings acording to python’s type()) are encoded in a format other that utf-8, but it thows me the following error:

'ascii' codec can't decode byte 0xc3 in position 14: ordinal not in range

Those escaped characters seems very strange to me, not to mention that I don’t want unicode strings but the accented characters (something like {string: “NIÑO, ÁRBOL, HÉROE”}), I know it’s possible because I’ve seen some google services work with accents.

Some advise? maybe I’m doing something incredibly wrong that I haven’t realized, that’s why I described the full process.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:25:55+00:00Added an answer on June 16, 2026 at 12:25 am

    Try this in your views.py works fine for me

    from django.utils import simplejson
    from django.core.serializers.json import DjangoJSONEncoder
    
    def jsonService(request):
    
        myObjects = MyObjects.objects().filter( Q(...) )
        fields = [x.field for x in myObjects] # creates a list of all fileds 
    
        # it will create JSON object
        result=simplejson.dumps({
            'fileds':fileds,
         })
    
        return HttpResponse(result, mimetype='application/json')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I would like to run a str_replace or preg_replace which looks for certain words
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.