我有一个字符串,如下所述。
str="[{"id":"100","sal_id":10009,"playback_url":"http:www.example_com","profile":"v5","protocol":"ttp","vwidth":40,"vheight":30,"vbitrate":1200,"abitrate":160,"status":"queue"}]"
从上面的字符串中,我只想取playback_url值,即http:www.example.com.
我尝试过拆分,但不起作用。像
str.split("playback_url").join(',')
请帮我实现这一点。提前谢谢。
试试这个
require 'json'
str="[{"id":"100","sal_id":10009,"playback_url":"http:www.example_com","profile":"v5","protocol":"ttp","vwidth":40,"vheight":30,"vbitrate":1200,"abitrate":160,"status":"queue"}]"
result = JSON.parse(str)
[{"id"=>"100", "sal_id"=>10009, "playback_url"=>"http:www.example_com", "profile"=>"v5", "protocol"=>"ttp", "vwidth"=>40, "vheight"=>30, "vbitrate"=>1200, "abitrate"=>160, "status"=>"queue"}]
result.first["playback_url"]
=> "http:www.example_com"