gpt4 book ai didi

javascript - 重定向奇怪格式的 url

转载 作者:行者123 更新时间:2023-12-03 12:06:57 25 4
gpt4 key购买 nike

我试图让我的页面将我重定向到另一个页面,但 URL 的格式很奇怪。
它看起来像这样:

网址=http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/geocodeAddresses?addresses= {"records":[{"attributes":{"OBJECTID":1,"SingleLine":"380 New York St., Redlands, CA, 92373",}},{"attributes":{"OBJECTID":2 ,"SingleLine":"1 World Way, 洛杉矶, CA, 90045",}}]}&sourceCountry=USA&token=&f=pjson。

我猜我必须以某种方式解析它,但我不知道如何解析。

最佳答案

您必须使用 encodeURIComponent 对每个 URL 查询字符串参数进行编码(至少是动态的):

window.location.href = 'http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/geocodeAddresses?addresses=' + encodeURIComponent('{"records":[{"attributes":{"OBJECTID":1,"SingleLine":"380 New York St., Redlands, CA, 92373",}},{"attributes":{"OBJECTID":2,"SingleLine":"1 World Way, Los Angeles, CA, 90045",}}]}') + '&sourceCountry=USA&token=&f=pjson';

进一步阅读:Encode URL in JavaScript?

关于javascript - 重定向奇怪格式的 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25145202/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com