zoukankan      html  css  js  c++  java
  • 解决Python 2下的json.loads()导致的unicode编码问题,json数据转换前面带u,去掉字典类型前面的u

    https://blog.csdn.net/qq_24342335/article/details/84561341

    def unicode_convert(input):
    if isinstance(input, dict):
    return {unicode_convert(key): unicode_convert(value) for key, value in input.iteritems()}
    elif isinstance(input, list):
    return [unicode_convert(element) for element in input]
    elif isinstance(input, unicode):
    return input.encode('utf-8')
    else:
    return input
    ————————————————

    test = {"name": "扎克伯格", "age":18}
    print test
    test_json = json.dumps(test, ensure_ascii=False)
    print test_json
    test1 = json.loads(test_json)
    print test1
    test2 = unicode_convert(json.loads(test_json))
    print test2
    ————————————————

    {'age': 18, 'name': 'xe6x89x8exe5x85x8bxe4xbcxafxe6xa0xbc'}
    {"age": 18, "name": "扎克伯格"}
    {u'age': 18, u'name': u'u624eu514bu4f2fu683c'}
    {'age': 18, 'name': 'xe6x89x8exe5x85x8bxe4xbcxafxe6xa0xbc'}
    ————————————————
    版权声明:本文为CSDN博主「Wally~」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/qq_24342335/java/article/details/84561341

  • 相关阅读:
    第三部分:填写志愿的思路
    第二部分:志愿录取标准
    2017年浙江省高考志愿、录取闪电入门系列 目录
    七、程序包
    五、过程式编程和调试技巧
    四、表达式的计算
    三、函数与递归
    二、表操作
    一、MMA概述
    Java面向对象
  • 原文地址:https://www.cnblogs.com/angdh/p/12673009.html
Copyright © 2011-2022 走看看