首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >将unicode转换为Python抛出错误

将unicode转换为Python抛出错误
EN

Stack Overflow用户
提问于 2015-08-10 23:54:29
回答 2查看 141关注 0票数 0

我有android应用程序,它从移动应用程序发送短信,如下所示:

代码语言:javascript
运行
复制
my_dict = {\
u'1': u'"sender" : "dz-080008", "text" : "enjoy 10%cashback@amazon.in &15%cashback@amazon app with hdfcbank debit/credit cards on min.purchase of rs5000 12aug-max amount rs1500 *t&c: bit.ly/1isljll", "time" : "1439212386383", "name" : "shyam"', \
u'0': u'"sender" : "am-swiggy", "text" : "please use this otp: 195830", "time" : "1439226026974", "name" : "shyam"', \
u'3': u'"sender" : "md-dgenie", "text" : "your dudegenie code is 6632. welcome to the world of dudegenie! your wish, my command!", "time" : "1439155803426", "name" : "shyam"', \
u'2': u'"sender" : "vx-611112", "text" : "we value your association with us. please call us on 89XXXXXXXX for exclusive offer onlyfor your number 88XXXXXXXX.u can reach us from 10:00 am-06:00 pm", "time" : "1439191024750", "name" : "shyam"',\
}.

但我无法处理这个请求并将其存储在我的数据库中,因为应用程序将在单个请求中发送100条sms,而当我通过提取密钥值对来处理该请求时,其他请求就会出现。因此,为了克服这一问题,我将请求存储在数据库中的每个row.Each行中,其中包含一个字符串,如下所示:

代码语言:javascript
运行
复制
<QueryDict: {u'messages': [u'<QueryDict: {u\'10\': [u\'"sender" : "md-dgenie", "text" : "your dudegenie code is 6326. welcome to the world of dudegenie! your wish, my command!", "time" : "1439155575925", "name" : "p"\'], u\'1\': [u\'"sender" : "vm-olacab", "text" : "ola! your total bill for crn111085358 is rs 151. your invoice is on its way to your e-mail shyam.ns114@gmail.com. call us on 080-33553355 for any help.", "time" : "1439319374298", "name" : "p"\'], u\'0\': [u\'"sender" : "ad-hlpcht", "text" : "dear customer, 50% off on premium doorstep laundry. use the coupon code hc50. download the app now (bit.ly/help50chat) or give us a shout at 08039236390.", "time" : "1439356609276", "name" : "p"\'], u\'3\': [u\'"sender" : "vm-olacab", "text" : "say ola to your driver kiran m  (8711045873) for crn111085358. silver tata indica ka 51 a 3940  to pick you up @ 12:06 am, 12aug. please share https://www.olacabs.com/track/939u1pe0m with friends/family and let them track you. call 080-33553355 if you need help.", "time" : "1439318029414", "name" : "p"\'], u\'2\': [u\'"sender" : "vm-olacab", "text" : "ola! your cab has arrived on time. hop on to have an awesome experience with this ride!", "time" : "1439318244463", "name" : "p"\'], u\'5\': [u\'"sender" : "dm-020001", "text" : "get upto 40%off +extra rs150 off@nykaa freedom sale with hdfc bank debit/credit card. code: nykhdfc150 .min purchasers1500. validity 15thaug *t&c bit.ly/1wedi4r", "time" : "1439300971524", "name" : "p"\'], u\'4\': [u\'"sender" : "dm-044210", "text" : "1 week to go!top 400 breeze mobile web transactors to get inr 250* flipkart vouchers/week & ipad mini*t&c apply.start now on.sc.com/breezedownload-in stanchart", "time" : "1439303662943", "name" : "p"\'], u\'7\': [u\'"sender" : "dz-080008", "text" : "enjoy 10%cashback@amazon.in &15%cashback@amazon app with hdfcbank debit/credit cards on min.purchase of rs5000 till 12aug-max amount rs1500 *t&c: bit.ly/1isljll", "time" : "1439212386383", "name" : "p"\'], u\'6\': [u\'"sender" : "am-swiggy", "text" : "please use this otp: 195830", "time" : "1439226026974", "name" : "p"\'], u\'9\': [u\'"sender" : "md-dgenie", "text" : "your dudegenie code is 6632. welcome to the world of dudegenie! your wish, my command!", "time" : "1439155803426", "name" : "p"\'], u\'8\': [u\'"sender" : "vx-611112", "text" : "we value your association with us. please call us on 9739102435for exclusive offer onlyfor your number 889XXXXXXX .u can reach us from 10:00 am-06:00 pm", "time" : "1439191024750", "name" : "p"\']}>']}>

现在,打开这种unicode/string的最佳方法是什么。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-08-11 00:17:49

字符串几乎采用字典格式,但不被{}包围。我想你想要{“发件人”:“我-”

票数 1
EN

Stack Overflow用户

发布于 2015-08-11 00:59:17

我漏掉了什么?你想做什么?jsondem和ast导入的目标是什么?

这不足以满足你想要做的事情吗?

代码语言:javascript
运行
复制
import json

my_dict = {u'1': u'"sender" : "dz-080008", "text" : "enjoy 10%cashback@amazon.in &15%cashback@amazon app with hdfcbank debit/credit cards on min.purchase of rs5000 12aug-max amount rs1500 *t&c: bit.ly/1isljll", "time" : "1439212386383", "name" : "shyam"', u'0': u'"sender" : "am-swiggy", "text" : "please use this otp: 195830", "time" : "1439226026974", "name" : "shyam"', \
u'3': u'"sender" : "md-dgenie", "text" : "your dudegenie code is 6632. welcome to the world of dudegenie! your wish, my command!", "time" : "1439155803426", "name" : "shyam"', \
u'2': u'"sender" : "vx-611112", "text" : "we value your association with us. please call us on 89XXXXXXXX for exclusive offer onlyfor your number 88XXXXXXXX.u can reach us from 10:00 am-06:00 pm", "time" : "1439191024750", "name" : "shyam"',\
}

for i in my_dict.values():
    print json.dumps(i)

**产出**

“\”发件人“:\”dz-080008\,\"text\“:”在min.purchase of rs5000 12 app rs1500 *t&c: bit.ly/1 1isljll\“,\"time\”:\"1439212386383\",\“名称\”:\"shyam\"“发件人”:"dz-080008“上的hdfcbank借记卡/信用卡应用程序“文本”:“在min.purchase of rs5000 12 am rs1500 *t&c: bit.ly/1 1isljll”、"time“:"1439212386383”、"name“:"shyam”“\”发件人\“\\”发送方\ \"am-swiggy\“、\"text\”:\“am-swiggy\”、\“text\”:\“请使用此otp: 195830\”、\“时间”:\"1439226026974\",\“名称\”:\"shyam\"“发件人”:"am-swiggy","text“:”请使用此otp: 195830","time“:"1439226026974","name”:"shyam“”\“发送者\:\”dudegenie \“,\"text\”:\“dudegenie代码为6632”。欢迎来到愚昧的世界!您的愿望,我的命令!\“时间\”:\"1439155803426\",\“名称\”:\"shyam\"“发件人”:“dudegenie”,"text“:”您的杜德基代码是6632。欢迎来到愚昧的世界!您的愿望,我的命令!“,”时间“:"1439155803426",”名称“:"shyam”“\”发送者\"vx-611112\",\“文本”:\\“我们重视您与我们的联系。请致电89XXXXXXXX向我们提供独家优惠,电话号码88XXXXXX.u可以在上午10:00至下午06:00到达我们,\“时间”:\"1439191024750\",\“名称”:\ \"shyam\"“发件人”:"vx-611112",“文本”:“我们重视您与我们的联系”。请致电89XXXXXXXX向我们提供独家优惠,只限于您的电话88XXXXXXXX.u可于上午10:00至下午06:00联系我们,时间:"1439191024750",“姓名”:"shyam“

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31930997

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档