Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何将集合字符串转换为集合
示例变量:
string_txt = "[id:2,name:'myname',age:'20']"
我想用它作为实例:
string_txt.id >> 2 string_txt.name >> "myname" ...
您可以使用Eval该类:
Eval
def stringTxt = "[id:2,name:'myname',age:'20']" def map = Eval.me( stringTxt ) assert map.name == 'myname'
当然,如果除了将 Map 放入字符串之外还有其他方法,您可能应该这样做。评估文本可能会带来很大的安全风险:-(