我有一个看起来像这样的传入字符串
data-url==\"\/entity\/id\/2439918080\"
如果我在此字符串上Println
,则会引发错误unknown escape sequence: /
参见http://play.golang.org/p/IbURcPc_gZ(评论第一个陈述并且有效)
但是,如果我将\/
替换为\u002F
,则会完美打印。实际传入的数据充满了这样的编码网址。无论如何我可以打印它而不必将其更改为\u002F
?
这是来自json的实际字符串
<div class="card2 media-container portrait" data-card2-name="summary_large_image"> <div class="js-macaw-cards-iframe-container" data-src="\/i\/entity\/tfw\/v1\/3298718080?cardname=summary_large_image&amp;earned=true" data-autoplay-src="\/i\/cards\/tfw\/v1\/632987845439918080?cardname=summary_large_image&amp;earned=true" data-card-name="summary_large_image" data-card-url="http:\/\/t.co\/QqWvUQMs5B" data-publisher-id="6721522" data-creator-id="" data-amplify-content-id="" data-amplify-playlist-url="" data-full-card-iframe-url="\/i\/cards\/tfw\/v1\/632987845439918080?cardname=summary_large_image&amp;earned=true" data-has-autoplayable-media="false"> <\/div> <\/div> <div class="entities-media-container js-media-container" style="min-height:0px"> <\/div> <div class="machine-translated-container"><\/div> <div class="stats-container stats-container "> <\/div> <div class="client-and-actions"> <span class="metadata"> <span>2:50 PM - 16 Aug 2015<\/span> &middot; <a class="permalink-link js-permalink js-nav" href="\/intifada\/status\/632987845439918080" tabindex="-1">Details<\/a> <\/span> <\/div> <\/div> \"\n\n\n\n\n\n\n\n data-you-follow=\"true\"\n data-follows-you=\"false\"\n data-you-block=\"false\"\n\n\n\n\n\u003e\n\n\n \u003cdiv class=\"context\"\u003e\n \n \n \u003c\/div\u003e\n \u003cdiv class=\"content\"\u003e\n\n \n \u003cdiv class=\"stream-item-header\"\u003e\n
感谢。
答案 0 :(得分:1)
如果您只是想获得一个有效的字符串:
package main
import "fmt"
import("strings")
func main() {
s := `data-url==\"\/entity\/id\/2439918080\"`
s = strings.Replace(s,"\\","",-1)
println(s)
//Replace \/ with \u002F works fine
fmt.Println("data-url==\"\u002Fentity\u002Fid\u002F2439918080\"")
}