【问题标题】:How to check if a URL has a matching ending as a json string如何检查 URL 是否具有匹配的结尾作为 json 字符串
【发布时间】: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


    【解决方案1】:

    首先extract url variables,假设您知道const tags 中有所需的值;

    然后,使用类似 json 的

    const data = {
      "Name": {
        "main": "hello"
        "tags": ["hello", "test"]
       }
    };
    

    data['Name'].tags.some( t => t === tags); 为您提供布尔值

    【讨论】:

    • 我不明白,这是否检查json标签是否与url相同?
    • 我检查url是否有?tags=hello?tags=test
    • 我就是这么做的-_-
    • 是否打印 JSON 字符串?
    猜你喜欢
    • 1970-01-01
    • 2012-09-30
    • 2015-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-08
    相关资源
    最近更新 更多