【发布时间】:2017-03-08 13:47:56
【问题描述】:
这可能是一个非常简单的问题,但我无法解决它。
在我的 python 控制台中我这样做:
request.request.data.get('comment')
我收到{u'price': u'21', u'unit': u'30\xd730', u'name': u'test', u'comments': u'check'}
comment的值原来是:
"comments" : "check",
"name" : "test",
"price" : "21",
"unit" : "30×30"(multiplication sign x)
我怎样才能解决这个问题,使我得到request.request.data.get('comment') 为{u'price': u'21', u'unit': u'30x30', u'name': u'test', u'comments': u'check'}?
我尝试使用:
request.request.data.get('comment').get('unit').encode('utf-8')
但它返回'30\xc3\x9730'
我想将/xd 转换为ascii。
【问题讨论】:
-
使用
str函数获取字符串str(request.request.data.get('comment')) -
{u'price': u'21', u'unit': u'30\\xd730', u'name': u'test', u'cmets': u'check '} 得到了这个。
标签: python string python-2.7 encoding