Processing list in golang

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

Processing list in golang

问题

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

编辑:
函数如下:

func MethodProcess() {
  dataList := dataList{}
  // 调用 web service 方法
  webres = MethodFromWeb()
  err := xml.Unmarshal(webres, &dataList)
  return dataList
}

输出:

{{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 :

func MethodProcess()
{
  dataList := dataList{}
  //Call webservice method
  webres = MethodFromWeb()
	err := xml.Unmarshal(webres, &dataList)
  return dataList
}

The output:

{{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

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

这将打印出:

matches = []string{"arg1", "desc", "High", "Low", "InnerDescription"}
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)

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

Which prints

matches = []string{"arg1", "desc", "High", "Low", "InnerDescription"}
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:

确定