dongyuan1984 2018-11-28 05:10
浏览 147
已采纳

将符文转换成字符串

I am trying to convert s := '{"selector:"{"Status":"open"}"}' to type string, as I need to pass this as an argument to a query using GetQueryResult().

I have tried UnescapeString, it only accepts string as argument:

fmt.Println("args " ,html.UnescapeString(s)

but s is a Go rune.

  • 写回答

1条回答 默认 最新

  • duanping1632 2018-11-28 05:25
    关注

    The Go Programming Language Specification

    String literals

    Rune literals


    Use string raw literal back quotes, not rune literal single quotes.


    For example,

    package main
    
    import (
        "fmt"
    )
    
    func main() {
        s := `{"selector:"{"Status":"open"}"}`
        fmt.Printf("type %T: %s", s, s)
    }
    

    Playground: https://play.golang.org/p/lGARb35VHTv

    Output:

    type string: {"selector:"{"Status":"open"}"}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。