zoukankan      html  css  js  c++  java
  • jsonp跨域请求响应结果处理函数(python)

    接口测试跨域请求接口用的jsonp,需要将回调函数里的json字符串提取出来。

    jsonp跨域请求的响应结果格式: callback_functionname(json字符串)。

    #coding:utf-8
    
    import json
    
    def jsonp_to_json(jsonp_string):
        """get jsonstr from jsonpstr=callback(jsonstr)"""
        left = jsonp_string.find('(') #找到第一个(的索引
        json_string = json.loads(jsonp_string[left+1:-1])  # 取callback()括号里的内容
        return json_string

    the end!

  • 相关阅读:
    面试题练习
    小作业7
    小作业6,7
    小作业
    坦克大战
    面试题
    20181213作业
    20181212作业
    20181211作业
    第三周周末作业
  • 原文地址:https://www.cnblogs.com/dinghanhua/p/10246533.html
Copyright © 2011-2022 走看看