英文:
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的简洁模式。
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
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"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论