Javascript 当作为req.query传递时,带有hashtag()的文本在后端消失

Javascript 当作为req.query传递时,带有hashtag()的文本在后端消失,javascript,node.js,express,Javascript,Node.js,Express,我试图在req.query中传递一个带有hashtag的字符串,以将其解析为JSON http://localhost:3000/link/?items=[{"quantity":1,"_id":"00001","box":"item01","desc":"#description1"}] 但是当它到达后端节点时,+Express req.query变为

我试图在req.query中传递一个带有hashtag的字符串,以将其解析为JSON

http://localhost:3000/link/?items=[{"quantity":1,"_id":"00001","box":"item01","desc":"#description1"}]
但是当它到达后端节点时,+Express req.query变为

如您所见,hashtag的描述刚刚消失,因此触发了SyntaxError:当被解析为JSON时,JSON输入*意外结束。

使用encodeURIComponent:

http://localhost:3000/link/?items=[{"quantity":1,"_id":"00001","box":"item01","desc":"#description1"}]
使用以下组件:


您需要对items参数进行URL编码。特别是角色,即。http://localhost:3000/link/?items=%5B%7B%22quantity%22%3A1%2C%22_id%22%3A%2200001%22%2C%22box%22%3A%22item01%22%2C%22desc%22%3A%22%23description1%22%7D%5Dis 有一种方法可以动态执行此操作吗?您需要对items参数进行URL编码。特别是角色,即。http://localhost:3000/link/?items=%5B%7B%22quantity%22%3A1%2C%22_id%22%3A%2200001%22%2C%22box%22%3A%22item01%22%2C%22desc%22%3A%22%23description1%22%7D%5Dis 有一种方法可以动态执行此操作吗?当我传递您提供的示例时,它起到了作用,但我正在使用一种方法将值传递到url窗口。location.href=/return/?items=+encodeURIComponentthis.selectedItems;在后端,它发送[Object]@Kevz对您不起作用吗?它没有解析req.query值给我SyntaxError:JSON中位置处的意外标记o1@KevzencodeURIComponentJSON.stringifyobjIt在我传递您提供的示例时起作用,但我正在使用一种方法将值传递到url窗口。location.href=/return/?items=+encodeURIComponentthis.selectedItems;在后端,它发送[Object Object]@Kevz,这对您不起作用吗?它没有解析req.query值,这给了我SyntaxError:JSON中位置处的意外标记o1@KevzencodeURIComponentJSON.stringifyobj
let url = 'http://localhost:3000/link/?items=' 
  + encodeURIComponent('[{"quantity":1,"_id":"00001","box":"item01","desc":"#description1"}]');