12345678910111213141516171819202122232425262728293031323334353637383940 |
- package main
- import (
- "encoding/xml"
- "strings"
- )
- func main() {
- s := "234.32.12.34:4222"
- idx := strings.LastIndex(s, ":")
- ip := s[:idx]
- port := strings.TrimLeft(s[idx:], ":")
- println(ip, port)
- var t HotelOrderValidateRES
- str := `<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Result><Message></Message><ResultCode>0</ResultCode><CreateOrderValidateKey></CreateOrderValidateKey><InventoryPrice>[{"date":"2020-08-03","price":165000,"quota":1}]</InventoryPrice></Result>`
- err := xml.Unmarshal([]byte(str), &t)
- if nil != err {
- panic(err)
- }
- var bt []byte
- println(t.InventoryPrice)
- bt, err = xml.Marshal(t)
- if nil != err {
- panic(err)
- }
- println(string(bt))
- }
- type BaseOrderRES struct {
- XMLName xml.Name `xml:"Result"`
- Message string `xml:"Message"`
- ResultCode int `xml:"ResultCode"`
- }
- type HotelOrderValidateRES struct {
- *BaseOrderRES
- CreateOrderValidateKey string `xml:"CreateOrderValidateKey"`
- InventoryPrice string `xml:"InventoryPrice"`
- }
|