Processing list in golang

huangapple go评论115阅读模式
英文:

Processing list in golang

问题

我正在尝试处理来自golang中的method()的数据,输出的格式如下所示,这是一个示例。

编辑:
函数如下:

  1. func MethodProcess() {
  2. dataList := dataList{}
  3. // 调用 web service 方法
  4. webres = MethodFromWeb()
  5. err := xml.Unmarshal(webres, &dataList)
  6. return dataList
  7. }

输出:

  1. {{arg1}desc[{ High Low [InnerDescription]}]}

输出基本上不是json格式,所以如果我想提取数据"High",数据是以什么格式存在的?

是否可能从中提取数据?

英文:

I am trying to process the data from a method() in golang, the output is in this format which is a sample one.

Edit:
The function is :

  1. func MethodProcess()
  2. {
  3. dataList := dataList{}
  4. //Call webservice method
  5. webres = MethodFromWeb()
  6. err := xml.Unmarshal(webres, &dataList)
  7. return dataList
  8. }

The output:

  1. {{arg1}desc[{ High Low [InnerDescription]}]}

The output is not basically in the json format ,so If I want to extract the data as "High",in what format is the data is in ?

is it possible to extract the data from it?

答案1

得分: 3

我不认识那种数据格式。

你可以使用yacc创建一个语法来解析它。

或者使用regexp的简洁模式。

Playground

  1. in := `{{arg1}desc[{ High Low [InnerDescription]}]}`
  2. matcher := regexp.MustCompile(`^\{\{(.*?)\}(.*?)\[\{\s*(.*?)\s+(.*?)\s*\[(.*?)\]\}\]\}`)
  3. match := matcher.FindStringSubmatch(in)
  4. fmt.Printf("matches = %#v\n", match[1:])
  5. fmt.Printf("High = %q\n", match[3])

这将打印出:

  1. matches = []string{"arg1", "desc", "High", "Low", "InnerDescription"}
  2. High = "High"
英文:

I don't recognise that data format.

You can either parse it with a grammar you make using yacc.

Or use the brutal minimalism of regexp

(Playground)

  1. in := `{{arg1}desc[{ High Low [InnerDescription]}]}`
  2. matcher := regexp.MustCompile(`^\{\{(.*?)\}(.*?)\[\{\s*(.*?)\s+(.*?)\s*\[(.*?)\]\}\]\}`)
  3. match := matcher.FindStringSubmatch(in)
  4. fmt.Printf("matches = %#v\n", match[1:])
  5. fmt.Printf("High = %q\n", match[3])

Which prints

  1. matches = []string{"arg1", "desc", "High", "Low", "InnerDescription"}
  2. High = "High"

huangapple
  • 本文由 发表于 2014年8月27日 14:22:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/25520217.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定