jsonp跨域请求响应结果处理函数(python)

接口测试遇到jsonp请求,需要将json字符串提取出来转成python的dict数据。

jsonp跨域请求响应结果格式: callback(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

  

猜你喜欢

转载自www.cnblogs.com/dinghanhua/p/10246533.html