浏览代码

规范str到json的过程

skyfffire 2 年之前
父节点
当前提交
dc2a489ad5
共有 2 个文件被更改,包括 19 次插入5 次删除
  1. 4 5
      arbitrage/api/blockchain_api.go
  2. 15 0
      arbitrage/api/utils.go

+ 4 - 5
arbitrage/api/blockchain_api.go

@@ -44,14 +44,13 @@ func (a *BlockchainApi) V2LpCountByChainId(request V2LpCountByChainIdRequest) (V
 	jsonData, _ := json.Marshal(request)
 
 	rstStr, err := HttpPost(url, jsonData)
+	result := V2LpCountByChainIdResult{}
 	if err != nil {
-		return V2LpCountByChainIdResult{}, err
+		return result, err
 	}
 
-	result := V2LpCountByChainIdResult{
-		Origin: rstStr,
-	}
-	json.Unmarshal([]byte(rstStr), &result)
+	result.Origin = rstStr
+	ParseJsonStringToObject(rstStr, result)
 
 	return result, err
 }

+ 15 - 0
arbitrage/api/utils.go

@@ -0,0 +1,15 @@
+package api
+
+import (
+	"encoding/json"
+	"github.com/ethereum/go-ethereum/log"
+)
+
+func ParseJsonStringToObject(str string, v interface{}) {
+	err := json.Unmarshal([]byte(str), v)
+
+	if err != nil {
+		log.Error("Parse json error", "err", err)
+		log.Error(str)
+	}
+}