js 获取单引号中的数据
时间: 2023-06-11 19:08:46 浏览: 65
你可以使用正则表达式来获取单引号中的数据,例如:
```javascript
const str = "Hello 'world'!";
const pattern = /'([^']*)'/; // 匹配单引号中的内容
const match = str.match(pattern);
const data = match ? match[1] : ''; // 获取匹配到的内容
console.log(data); // 输出:world
```
这里的正则表达式 `/'([^']*)'/` 匹配由单引号包围的任意字符,其中 `[^']` 表示除了单引号之外的任意字符,`*` 表示重复零次或多次。
相关问题
import service from ".." //获取歌单详情页的数据 export function getMusicItemList(data){ return service({ method:"GET", url:"/playlist/detail?id=${data}", }) }为什么获取参数错误
问题可能出在你的代码中 `${data}` 这个地方。在 JavaScript 中,使用 `${variable}` 的方式可以将变量的值插入到字符串中。但是,您的代码中使用了单引号而不是反引号(模板字符串),所以 `${data}` 并没有被正确地解析成变量值,而被认为是字符串 `data`。正确的代码应该是这样的:
```
import service from ".." //获取歌单详情页的数据
export function getMusicItemList(data){
return service({
method: "GET",
url: `/playlist/detail?id=${data}`,
})
}
```
这里使用了反引号来定义字符串模板,`${data}` 被正确地解析成了传入的变量。
详细解释代码def getData(domain,projectId,importId,riskAnalysisIndexId): url = f'{domain}/business/projectSite/getPythonParam/{projectId}/{importId}/{riskAnalysisIndexId}' res = requests.get(url=url).json() if res["code"] != 200: print(f"获取数据!({res.get('msg')})") return None else: return res["data"] try: # 获取Java接口 #获取参数 data = sys.argv[1].replace("'", '"') parameters = json.loads(data) domain = parameters['domain'] projectId = parameters['projectId'] importId = parameters['importId'] riskAnalysisIndexId = parameters['riskAnalysisIndexId'] # 获取数据 js = getData(domain,projectId,importId,riskAnalysisIndexId) #已导入系统内的源数据文件清单 filename = pd.DataFrame(js["fileList"]) #已纳入本次分析的研究中心列表 site_info = pd.DataFrame(js["siteList"]) infile_path1 = " ".join( filename[filename["originalName"] == "GOCS-H101-E02_eCRFEntrySDVeSignReport.xlsx"][ "fileUrl" ].tolist() ) #读取数据 sdv_rep = pd.read_excel(infile_path1, dtype={"Site No.":str})
这段代码的功能是通过调用一个接口获取数据,并进行数据处理和分析。
首先定义了一个函数 `getData`,它接受四个参数:`domain`、`projectId`、`importId` 和 `riskAnalysisIndexId`。在函数体内,通过拼接 URL 的方式构造了一个请求地址,并使用 `requests.get` 方法发送 GET 请求获取数据,并将返回的结果解析为 JSON 格式。如果返回的状态码不等于 200,则打印错误信息并返回 None;否则,返回数据中的 "data" 字段。
接下来使用 `try-except` 块来处理异常。首先通过 `sys.argv[1]` 获取命令行参数,然后使用 `replace` 方法将单引号替换为双引号,再使用 `json.loads` 方法将参数转换为字典格式。然后从字典中获取 `domain`、`projectId`、`importId` 和 `riskAnalysisIndexId` 的值。
接着调用 `getData` 函数,传入获取到的参数值,将返回的结果赋值给变量 `js`。然后根据返回的数据,分别构造了名为 `filename` 和 `site_info` 的 DataFrame 对象。
最后,根据条件筛选出符合条件的文件路径,并将其转换为字符串形式赋值给变量 `infile_path1`。然后使用 `pd.read_excel` 方法读取该文件,并指定 "Site No." 列的数据类型为字符串(str),最终结果存储在变量 `sdv_rep` 中。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)