Answer the question
In order to leave comments, you need to log in
Parsing string fields in json in golang is displayed with quotes. How to remove them?
Client sends json like this
{"function":"GroupAdd","data":"New group name"}
I parse json
type struct_json struct {
Function string
Data json.RawMessage
}
...
var Struct_json = &struct_json{}
var b_clientMessage =[]byte(clientMessage)
err := json.Unmarshal(b_clientMessage, Struct_json )
if err != nil {
log.Println("error:", err)
}
switch Struct_json.Function {
case "GroupAdd":
GroupAdd(Id,string(Struct_json.Data))
...
func GroupAdd(UserId int, Name string){
query := "insert into groups(Name,UserId) values (?,?)"
if new_query_exec(query, Name, UserId){ //тут записывается в БД
Refresh_Groups()
}
}
Answer the question
In order to leave comments, you need to log in
The quotes are displayed because you specified the json.RawMessage type for the Data field. This type is designed just to disable parsing of the field, i.e., output the field in its original format. If you replace json.RawMessage with a string, then the quotes will disappear.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question