Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jsonpb,为什么要将int64解码为json,结果是字符串。如int64 str=10-->;str:“;10“;_Json_Go - Fatal编程技术网

jsonpb,为什么要将int64解码为json,结果是字符串。如int64 str=10-->;str:“;10“;

jsonpb,为什么要将int64解码为json,结果是字符串。如int64 str=10-->;str:“;10“;,json,go,Json,Go,问题: 为什么要在值周围附加“\”?因为在javascript中表示整数的方式意味着最大整数是(2乘以53的幂)-1(请参阅) int64中的最大整数大于该整数,因此为了防止出现大整数,库会改为使用一串数字 当javascript数字被签名时,大负数也会被签名。您必须询问库作者。这是一个实现细节,不受JSON规范的约束。@vorspring给出的原因可能是为了取消javascript的签名。 //code:630 //jsonpb, why int64 -> json is string

问题:


为什么要在值周围附加“\”?

因为在javascript中表示整数的方式意味着最大整数是(2乘以53的幂)-1(请参阅)

int64
中的最大整数大于该整数,因此为了防止出现大整数,库会改为使用一串数字


当javascript数字被签名时,大负数也会被签名。

您必须询问库作者。这是一个实现细节,不受JSON规范的约束。@vorspring给出的原因可能是为了取消javascript的签名。
//code:630

//jsonpb, why int64 -> json is string. like 10-->"10"

//https://github.com/golang/protobuf/blob/master/jsonpb/jsonpb.go

// Default handling defers to the encoding/json library.
b, err := json.Marshal(v.Interface())
if err != nil {
    return err
}
needToQuote := string(b[0]) != `"` && (v.Kind() == reflect.Int64 || v.Kind() == reflect.Uint64)
if needToQuote {
    out.write(`"`)
}
out.write(string(b))
if needToQuote {
    out.write(`"`)
}