Here is json string:
{
"app":"${host}\":\"${post}"
}
How unwrap strings? Eg how to produce this:
{
app:${host}":"${post}
}
Leading and trailing double quotes are deleted, escaped double quotes become unescaped.
How to do this with ruby?
Also
In java I can use appache commons StringEscapeUtil.unescapeJson Is there analog in ruby?
Important
string.replace("\\"", "")
and string.replace("\\\\\\"", "")
but it would be nice to use some out-of-the-box function (if it is). require 'json'
str =<<'END_OF_STRING'
{
"app":"${host}\":\"${post}"
}
END_OF_STRING
puts str
puts str.gsub(/[\\]" | ["]/x, '\"' => '"', '"' => '')
--output:--
{
"app":"${host}\":\"${post}"
}
{
app:${host}":"${post}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.