我想将嵌套的 xml 解封为戈朗结构。我想要取消编组的 xml 如下所示。
<?xml version="1.0" encoding="UTF-8"?>
<status>
<authorized>true</authorized>
<plan>Basic</plan>
<usage_reports>
<usage_report metric="hits" period="day">
<period_start>2021-07-20 00:00:00 +0000</period_start>
<period_end>2021-07-21 00:00:00 +0000</period_end>
<max_value>1000000</max_value>
<current_value>0</current_value>
</usage_report>
<usage_report metric="hits.82343" period="day">
<period_start>2021-07-20 00:00:00 +0000</period_start>
<period_end>2021-07-21 00:00:00 +0000</period_end>
<max_value>1000000</max_value>
<current_value>0</current_value>
</usage_report>
</usage_reports>
</status>
为了取消马歇尔,我定义了两个围棋结构,如下所示。
// UsageReport represents the usage report of a particular metric.
type UsageReport struct {
Usage string `xml:"usage_report,chardata"`
Metric string `xml:"metric,attr"`
Period string `xml:"period,attr"`
Start string `xml:"period_start"`
End string `xml:"period_end"`
Max int64 `xml:"max_value"`
Current int64 `xml:"current_value"`
}
// AuthResponse represents the structure of the response from authorize calls.
type AuthResponse struct {
Status xml.Name `xml:"status"`
Authorized bool `xml:"authorized"`
Plan string `xml:"plan"`
Usages []UsageReport `xml:"usage_reports"`
}
但是当我尝试使用 解组时,只有 和 值被取消组。解组的结果如下所示。xml.UnmarshalPlanAuthorized
XML: {{ } true Basic []}
互换的青春
小唯快跑啊
手掌心
随时随地看视频慕课网APP
相关分类