简体   繁体   English

发送 map 时出现奇怪的问题,其值中包含“,”,作为 groovy 中的参数

[英]weird issue when sending a map with a value that has "," in it, as parameter in groovy

here is my situation:这是我的情况:

func1(){
   def value1 = "gal,dan"
   def prop = ['names': value1]
   func2(prop)
}

func2(prop){
   def params_str = prop.collect { k, v -> "k=v" }.join(' ')
}

now i'm getting: dan has no value meaning it treats the ',' inside the first value as the ',' to go to the next key value pair现在我得到:dan 没有值意味着它将第一个值中的 ',' 视为 ',' 到 go 到下一个键值对

anyone got an idea how to fix it?任何人都知道如何解决它?

i tried encoding and decoding it but its pointless since when i decode it it still treats the ',' as go to the next key value pair我尝试对其进行编码和解码,但它毫无意义,因为当我解码它时,它仍然将“,”视为下一个键值对的 go

i tried sending it like ['names': "$value1"] and it failed too i tried adding "/'gal,dan/'" and it failed too我尝试像 ['names': "$value1"] 一样发送它,但它也失败了 我尝试添加 "/'gal,dan/'" 但它也失败了

i expect names=gal,dan我希望 names=gal,dan

You need to surround the value1 variable with quotes to indicate that it is a single string value.您需要用引号将 value1 变量括起来,以指示它是单个字符串值。

func1() {
   def value1 = "gal,dan"
   def prop = ['names': "'$value1'"]
   func2(prop)
 }

func2(prop) {
   def params_str = prop.collect { k, v -> "k=$v" }.join(' ')
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM