【发布时间】:2020-11-02 17:30:08
【问题描述】:
如果我的 URL 是“example.com/API?tags=test”并且我有一个 json 文件,其中包含:
"Name": {
"main": "hello"
"tags": ["hello", "test"]
}
如何检查 URL 是否与 json 值有相同的标签,然后打印 json 字符串?
【问题讨论】:
标签: javascript json url
如果我的 URL 是“example.com/API?tags=test”并且我有一个 json 文件,其中包含:
"Name": {
"main": "hello"
"tags": ["hello", "test"]
}
如何检查 URL 是否与 json 值有相同的标签,然后打印 json 字符串?
【问题讨论】:
标签: javascript json url
首先extract url variables,假设您知道const tags 中有所需的值;
然后,使用类似 json 的
const data = {
"Name": {
"main": "hello"
"tags": ["hello", "test"]
}
};
data['Name'].tags.some( t => t === tags); 为您提供布尔值
【讨论】:
?tags=hello或?tags=test