temp.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package main
  2. import (
  3. "encoding/xml"
  4. "strings"
  5. )
  6. func main() {
  7. s := "234.32.12.34:4222"
  8. idx := strings.LastIndex(s, ":")
  9. ip := s[:idx]
  10. port := strings.TrimLeft(s[idx:], ":")
  11. println(ip, port)
  12. var t HotelOrderValidateRES
  13. str := `<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Result><Message></Message><ResultCode>0</ResultCode><CreateOrderValidateKey></CreateOrderValidateKey><InventoryPrice>[{&#34;date&#34;:&#34;2020-08-03&#34;,&#34;price&#34;:165000,&#34;quota&#34;:1}]</InventoryPrice></Result>`
  14. err := xml.Unmarshal([]byte(str), &t)
  15. if nil != err {
  16. panic(err)
  17. }
  18. var bt []byte
  19. println(t.InventoryPrice)
  20. bt, err = xml.Marshal(t)
  21. if nil != err {
  22. panic(err)
  23. }
  24. println(string(bt))
  25. }
  26. type BaseOrderRES struct {
  27. XMLName xml.Name `xml:"Result"`
  28. Message string `xml:"Message"`
  29. ResultCode int `xml:"ResultCode"`
  30. }
  31. type HotelOrderValidateRES struct {
  32. *BaseOrderRES
  33. CreateOrderValidateKey string `xml:"CreateOrderValidateKey"`
  34. InventoryPrice string `xml:"InventoryPrice"`
  35. }