隔江千里
编辑此编辑改进并解释了基于注释的答案。var search = location.search.substring(1);JSON.parse('{"' + decodeURI(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}')例解析abc=foo&def=%5Basf%5D&xyz=5分五个步骤:decdeURI:abc=foo&def=[asf]&xyz=5转义引号:相同,因为没有引号替换&:abc=foo","def=[asf]","xyz=5取代=:abc":"foo","def":"[asf]","xyz":"5有卷曲和引号:{"abc":"foo","def":"[asf]","xyz":"5"}这是合法的JSON。阿改进解允许搜索字符串中的更多字符。它使用一个REVERVER函数对URI进行解码:var search = location.search.substring(1);JSON.parse('{"' + search.replace(/&/g, '","').replace(/=/g,'":"') + '"}', function(key, value) { return key===""?value:decodeURIComponent(value) })例search = "abc=foo&def=%5Basf%5D&xyz=5&foo=b%3Dar";施予Object {abc: "foo", def: "[asf]", xyz: "5", foo: "b=ar"}原始答案单线:JSON.parse('{"' + decodeURI("abc=foo&def=%5Basf%5D&xyz=5".replace(/&/g, "\",\"").replace(/=/g,"\":\"")) + '"}')