zoukankan      html  css  js  c++  java
  • python开发笔记-str转字典

    后台接收到post请求数据格式为json格式的字符串,不能直接用字典的get方法

    909090909090909090909090909090909
    Internal Server Error: /get_data/sql_server/
    Traceback (most recent call last):
      File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/exception.py", line 41, in inner
        response = get_response(request)
      File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/base.py", line 187, in _get_response
        response = self.process_exception_by_middleware(e, request)
      File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/base.py", line 185, in _get_response
        response = wrapped_callback(request, *callback_args, **callback_kwargs)
      File "/home/get_data_from_sqlserver/get_data/views.py", line 45, in get_data_from_sql_server
        request_token = request_data.get('token')
    AttributeError: 'str' object has no attribute 'get'

    json dict格式的字符串,转字典,可以用eval方法

    例:

    >>> test = "{'name' : 'jesson', 'sex' : 'male', 'age': 28}"
    >>> test01=eval(test)
    >>> type(test)
    <class 'str'>
    >>> 
    >>> type(test01)
    <class 'dict'>
  • 相关阅读:
    所有时间测试函数
    时间函数应用 time
    50个c/c++源代码网站
    ASN.1详解
    SNMP协议
    SNMP协议详解
    大数据需要建立规则和标准
    常用的三层架构设计
    构建大型网站架构十步骤
    iOS 应用程序内部国际化,不跟随系统语言
  • 原文地址:https://www.cnblogs.com/hellojesson/p/11466088.html
Copyright © 2011-2022 走看看