zoukankan      html  css  js  c++  java
  • pythonl输出的预警消息中的json串的中文展示乱码(中文的unicode码)

    来源:ctrip
    接口名称:ReviewStandartAPI
    错误信息:[{'ReviewTime': u'u63a5u53e3u8fd4u56deu7684u70b9u8bc4u65f6u95f4u6233u4e0du662fu79d2u7ea7u768410u4f4du30022194034227563614'}, {'ReviewTime': u'u63a5u53e3u8fd4u56deu7684u70b9u8bc4u65f6u95f4u6233u4e0du662fu79d2u7ea7u768410u4f4du30022194034227563614'}, {'ReviewTime': u'u63a5u53e3u8fd4u56deu7684u70b9u8bc4u65f6u95f4u6233u4e0du662fu79d2u7ea7u768410u4f4du30022194034227563614'}, {'ReviewTime': u'u63a5u53e3u8fd4u56deu7684u70b9u8bc4u65f6u95f4u6233u4e0du662fu79d2u7ea7u768410u4f4du30022194034227563614'}, {'ReviewTime': u'u63a5u53e3u8fd4u56deu7684u70b9u8bc4u65f6u95f4u6233u4e0du662fu79d2u7ea7u768410u4f4du30022194034227563614'}]

    这里输出的中文全是unicode码,如何让其显示中文呢?

    第一种方法:print res_content.decode('raw_unicode_escape')

    第二种方汉:json.dumps( res_conten,ensure_ascii=False)

    可是这两种方法都是打印时能看到中文,但写到预警邮件里就不是了。为什么呢?

    后来发现,我消费1000条数据,每条数据发现的问题都存储在list里,改成存储在dict中就可以了。

    for items in data["errorMSG"]:
    print json.dumps(items).decode("unicode-escape")
    content[u"错误信息"] = json.dumps(items).decode("unicode-escape")

    所有错误存储在dict中就能正确展示中文了。
    格式如下:
    来源:ctrip
    接口名称:ReviewStandartAPI
    错误信息:
    {
        '101109': {
            'ReviewTime': u'u63a5u53e3u8fd4u56deu7684u70b9u8bc4u65f6u95f4u6233u4e0du662fu79d2u7ea7u768410u4f4du30022199734227563563'
        },
        '101110': {
            'ReviewTime': u'u63a5u53e3u8fd4u56deu7684u70b9u8bc4u65f6u95f4u6233u4e0du662fu79d2u7ea7u768410u4f4du30022199734227563563'
        }
    }
  • 相关阅读:
    l2tp ubuntu
    my emacs fav config
    2048小游戏源码(vue自定义指令使用)
    Vue 脚手架新建项目
    vue中修改router定义的name值
    只能输入金额格式的input
    前端开发中UI问题处理
    form表单提交Ajax请求后不跳转
    小程序中代替v-html用法
    小程序中分页加载问题
  • 原文地址:https://www.cnblogs.com/yoyoma0355/p/9227851.html
Copyright © 2011-2022 走看看