{"color":"red", "mrkdwn_in":["text"]}
to a structure in UnMarshal"mrkdwn_in":["text"]
does not maintain well
"mrkdwn_in": [{"text":"}]
or "mrkdwn_in":"
."mrkdwn_in": [{"text":"}]
or "mrkdwn_in":"
.package main
import(
"encoding/json"
"fmt"
)
type TestStructure {
Color string `json:`color``
MrkdwnIn[]MrkdwnIn`json: "mrkdwn_in"`
}
typeMrkdwnInstructure{
Text string `json:`text``
}
funcmain(){
jsonData1:="{\"color\":\"red\"',\"mrkdwn_in\":[\"text\"]}"
varbody TestStruct
json.Unmarshal([]byte(jsonData1), & body)
body.Color="blue"
varjsonData2[]byte
jsonData2,_=json.Marshal(body)
jsonDataText: =string(jsonData2)
fmt.Println(jsonDataText)
}
Now it's resolved.
MrkdwnIn[]MrkdwnIn`json: "mrkdwn_in"`
↓
MrkdwnIn[]string `json: "mrkdwn_in"`
© 2024 OneMinuteCode. All rights reserved.