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'
        }
    }
  • 相关阅读:
    linux安装jenkins
    如何将接口进行限流
    java线程池思想
    一次缓存评估过程
    docker
    linux基本操作
    【安卓】App自动化环境搭建
    sheill之文本处理工具
    Liunx vim编辑器
    Liunx 远程
  • 原文地址:https://www.cnblogs.com/yoyoma0355/p/9227851.html
Copyright © 2011-2022 走看看