How do I JSON serialize a Python dictionary?

后端 未结 5 2293
余生分开走
余生分开走 2020-12-07 11:06

I\'m trying to make a Django function for JSON serializing something and returning it in an HttpResponse object.

def json_response(something):
          


        
5条回答
  •  借酒劲吻你
    2020-12-07 11:49

    In python 2.6 and higher there is a nice JSON library, which has many functions among which is json.dumps() which serializes an object into a string.

    So you can do something like this:

    import json
    print json.dumps({'howdy' : True })
    

提交回复
热议问题