如今,我嘗試根據一個公共密鑰合并兩個jon。我在一個公共字段中輸入了兩個不同的JSON,我想基于公共密鑰合并兩個JSON的數據。兩種JSON之間的一種sql連接。JSON源自此代碼func Dati_plus(c *gin.Context) {oracle, err := http.Get("http://XXXX/XXX") if err != nil { panic(err) }defer oracle.Body.Close()mysql, err := http.Get("http://XXXX/XXX")if err != nil { panic(err)}defer mysql.Body.Close()oracleJSON, err := ioutil.ReadAll(oracle.Body)if err != nil { panic(err)}mysqlJSON, err := ioutil.ReadAll(mysql.Body)if err != nil { panic(err)}var oracleOUT map[string]interface{}var mysqlOUT map[string]interface{}json.Unmarshal([]byte(oracleJSON), &oracleOUT)json.Unmarshal([]byte(mysqlJSON), &mysqlOUT)a := map[string]interface{}{"result":mysqlOUT["result"]}b := map[string]interface{}{"result":oracleOUT["result"]}輸入中的JSON具有這種形式{"count":2,"result":[{"DESC":"2","NOMEmy":"PIPPO","COGNOMEmy":"PIPPO"},{"DESC":"7","NOMEmy":"PIPPO","COGNOMEmy":"PIPPO"}]{"count":2,"result":[{"DESC":"2","COS":"PIPPO","ROS":"PIPPO"},{"DESC":"7","COS":"PIPPO","ROS":"PIPPO"},{"DESC":"60","COS":"PIPPO","ROS":"PIPPO"}]如果我有兩個這樣的json函數的結果應該是{"count":2,"result":[{"DESC":"2","COS":"PIPPO","ROS":"PIPPO","NOMEmy":"PIPPO","COGNOMEmy":"PIPPO"},{"DESC":"7","COS":"PIPPO","ROS":"PIPPO","NOMEmy":"PIPPO","COGNOMEmy":"PIPPO"},{"DESC":"60","COS":"PIPPO","ROS":"PIPPO"}]如果可以幫助的話,這是我用于在兩個單值JSON之間進行合并的函數,但是我無法以正確的方式對其進行修改 func merge(dst, src map[string]interface{}, depth int) map[string]interface{} { if depth > MaxDepth { panic("Troppo Lungo") } for key, srcVal := range src { if dstVal, ok := dst[key]; ok { srcMap, srcMapOk := mapify(srcVal) dstMap, dstMapOk := mapify(dstVal) if srcMapOk && dstMapOk { srcVal = merge(dstMap, srcMap, depth+1) } } dst[key] = srcVal } return dst}請幫我。謝謝
- 1 回答
- 0 關注
- 360 瀏覽
添加回答
舉報
0/150
提交
取消