使用PERL one liner将字符串解码为不同的变量

时间:2010-07-29 18:12:45

标签: perl

我有以下字符串,我想根据字符串

将其解码为不同的变量

实施例

{"response":{"report":"fail","brand":"1.0","fail":{"message":"Invalid Number"}}}

{"response":{"report" : "pass", "brand" : "1.0", "payment" :{"paymentId":"4CA008DAAA41EC19C754EF"}}}

{"response":{"report":"fail","brand":"1.0","fail":{"message":"internal server problems."}}}

{"response" : {"report" : "pass", "brand" : "1.0", "email" :{"subject":"Notification","to":"TEST@TEST.COM"}}}

我想获得一个衬管命令或多个命令来将值提取到不同的变量中。

结果

Variable 1 = fail  variable 2 = 1.0 variable 3 = Invalid Number

Variable 1 = pass  variable 2 = 1.0 variable 3 = 4CA008DAAA41EC19C754EF

Variable 1 = fail  variable 2 = 1.0  variable 3 = internal server problems.

variabl 1 = pass variable 2 = 1.0 variable 3 = Notification variable 4 = TEST@TEST.COM  ( since there are 2 values in the inner most {} )

1 个答案:

答案 0 :(得分:2)

尝试使用适当的JSON解码器,例如http://search.cpan.org/perldoc?JSON

即使eval()有效(我有点怀疑),它也相当不安全,可以在你的机器上执行任意代码。哎哟。