我一直在為我的一個小項目編寫此代碼,我想解析一些看起來像這樣的JSON數(shù)據(jù):{ "payloads": [ { "xss": [ { "payload": "{{RANDSTR}}\"><scRiPT>alert(1)</ScrIPT>{{RANDSTR}}", "search": "{{RANDSTR}}\"><scRi" }, { "payload": "{{RANDSTR}}\"", "search": "{{RANDSTR}}\"" }, { "payload": "{{RANDSTR}}'", "search": "{{RANDSTR}}'" } ], "tpli": [ { "payload": "{{RANDSTR}}${{ {{RANDINT}} * {{RANDINT}} }}", "search": "{{RANDSTR}}{{RANDINT}}" }, { "payload": "{{RANDSTR}}{{ {{RANDINT}} * {{RANDINT}} }}", "search": "{{RANDSTR}}{{RANDINT}}" }, { "payload": "{{RANDSTR}}{! {{RANDINT}} * {{RANDINT}} !}", "search": "{{RANDSTR}}{{RANDINT}}" }, { "payload": "{{RANDSTR}}{% {{RANDINT}} * {{RANDINT}} %}", "search": "{{RANDSTR}}{{RANDINT}}" } ] } ]}這是我的結(jié)構(gòu)聲明:type Payload struct { Payload []struct { Payload string `json:"payload"` Search string `json:"search"` }}type Payloads struct { Payloads []Payload `json:"payloads"`}我知道這不是我應(yīng)該做的事情,但我不確定最好的方法。我不想指定鍵(xss,tpli等),因為我想輕松擴展此文件而無需修改Go文件。有人能為我指出如何實現(xiàn)這一目標(biāo)的正確方向嗎?
1 回答

寶慕林4294392
TA貢獻(xiàn)2021條經(jīng)驗 獲得超8個贊
將其建模為:
type Payloads struct {
Payloads []map[string][]Payload `json:"payloads"`
}
type Payload struct {
Payload string `json:"payload"`
Search string `json:"search"`
}
游樂場: https://play.golang.org/p/S6nnOKkADUO
- 1 回答
- 0 關(guān)注
- 128 瀏覽
添加回答
舉報
0/150
提交
取消