gpt4 book ai didi

go - 在 golang 中处理列表

转载 作者:IT王子 更新时间:2023-10-29 02:34:27 27 4
gpt4 key购买 nike

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

编辑:函数是:

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

输出:

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

输出基本上不是json格式,所以如果我想提取数据为“高”,数据是什么格式?

是否可以从中提取数据?

最佳答案

我不认识那种数据格式。

您可以使用 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"

关于go - 在 golang 中处理列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25520217/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com