开发者

decode a string into different variables using PERL one liner

I've the following strings which I would like to decode into different variables depending on the string

examples

{"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", "开发者_StackOverflow中文版email" :{"subject":"Notification","to":"TEST@TEST.COM"}}}

I want to get one liner command or multiple command to fetch values into different variables.

Results

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 {} )


Try to use a proper JSON decoder like http://search.cpan.org/perldoc?JSON

Even if eval() works (which I kinda doubt), it's rather unsafe, and can execute arbitrary code on your machine. Ouch.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜