芜湖不芜
我不确定我是否正确理解你想要什么,所以我写了一个片段:package mainimport ( "encoding/json" "fmt" "log")type Setting struct { Code1 string Code2 string Seq string}type entry struct { site string code string main string}func main() { entries := []entry{ {"", "0700-Shift", "010_A"}, {"", "2135-Packing", "030_C"}, {"", "3343-Check", "050_E"}, {"", "4355-Casting", "080_H"}, {"", "6903-ReDo Test", "020_B"}, {"", "2277-Scope chk", "080_H"}, } var jsonBlob = []byte(`[ {"010_A": [ { "Code1": "010_02", "Code2": "010_0231", "Seq": "000 Start" }, { "Code1": "010_08", "OP_CODE": "010_0822", "Seq": "010 Shift" } ], "020_B": [{ "Code1": "020_69", "Code2": "020_7011", "Seq": "000 ReDo Test" }, { "Code1": "020_27", "Code2": "", "Seq": "000 Redo Combine" } ], "080_H": [ { "Code1": "080_06", "Code2": "", "Seq": "005 Merge" }, { "Code1": "080_43", "Code2": "", "Seq": "010 Casting" }, { "Code1": "080_66", "Code2": "080_6621", "Seq": "100 Cooling" }, { "Code1": "080_66", "Code2": "2277", "Seq": "Test" } ]} ]`) datas := []map[string][]Setting{} if err := json.Unmarshal(jsonBlob, &datas); err != nil { log.Fatal(err) } for key, settings := range datas[0] { for _, setting := range settings { for k, e := range entries { if e.main == key && setting.Code2 == e.code[:4] { entries[k].site = setting.Seq } } } } fmt.Println(entries)}