dsaff82024 2018-10-29 02:47
浏览 65
已采纳

由于编码,解组返回空白对象

I'm attempting to unmarshal a raw json string. There seems to be an error with encoding but I can't quite figure it out.

package main

import (
    "encoding/json"
    "fmt"
    "log"
)

type Foo struct {
    Transmission string `json:"transmission"`
    Trim         string `json:"trim"`
    Uuid         string `json:"uuid"`
    Vin          string `json:"vin"`
}

func main() {

    var foo Foo

    sample := `{
        "transmission": "continuously\x20variable\x20automatic",
        "trim": "SL",
        "uuid" : "6993e4090a0e0ae80c59a76326e360a1",
        "vin": "5N1AZ2MH6JN192059"
    }`

    err := json.Unmarshal([]byte(sample), &foo)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(foo)

}

2009/11/10 23:00:00 invalid character 'x' in string escape code

It works if transmission entry is removed.

Here is a working playground.

  • 写回答

2条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥30 关于#网络安全#的问题:非对称加密验证
      • ¥20 关于线性代数里施密特正交化和QR分解的疑问
      • ¥15 matlab超类包含解析错误
      • ¥15 python拖拽文件问题
      • ¥15 执行import paddle代码出现错误如何解决?
      • ¥15 hisat2align exited with value 137
      • ¥15 寻找大学生合作开发软件(Delphi)
      • ¥30 AndroidBench&eMMC内存测试速度&Android
      • ¥15 W10 文件共享失败 怎么解决
      • ¥20 b站私信完整导出的方法