Deserialize query string to JSON object

后端 未结 7 1223
感情败类
感情败类 2021-01-04 01:21

Tried to find how to make {foo:\"bar\"} from ?...&foo=bar&... but googled and got only to jQuery.params which does the opposit

7条回答
  •  被撕碎了的回忆
    2021-01-04 02:18

    The URLSearchParams() constructor creates and returns a new URLSearchParams object.

    var url = new URL('https://example.com?foo=1&bar=2'); 
    var params = new URLSearchParams(url.search);
    

    https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/URLSearchParams

提交回复
热议问题