Skip to content

Commit 15bc850

Browse files
committed
fix json.Unmarshal bug,when param is (u)int64
1 parent 2af04ae commit 15bc850

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

error/errcode.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131

3232
log "github.com/cihub/seelog"
3333
"bytes"
34+
"strings"
3435
)
3536

3637
// ErrorCode struct
@@ -79,7 +80,19 @@ func Return(b interface{}) string {
7980
ret.Code = 1
8081
ret.Msg = "ok"
8182

82-
body, err := json.Marshal(ret)
83+
//fix json.Unmarshal bug,when param is (u)int64
84+
decoder := json.NewDecoder(strings.NewReader(string(buf)))
85+
decoder.UseNumber()
86+
para := make(map[string]interface{})
87+
err = decoder.Decode(&para)
88+
if err != nil {
89+
log.Error(err)
90+
panic(err)
91+
}
92+
93+
body, err := json.Marshal(para)
94+
95+
//body, err := json.Marshal(ret)
8396
if err != nil {
8497
log.Error(err)
8598
panic(err)

service/common/data/chain.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,20 +163,38 @@ func AccountInfo(account string) (*user_proto.AccountInfoData, error) {
163163
return nil, errors.New(string(body))
164164
}
165165

166-
resultBuf, err := json.Marshal(commonRet.Result)
166+
//fix json.Unmarshal bug,when param is (u)int64
167+
decoder := json.NewDecoder(strings.NewReader(string(body)))
168+
decoder.UseNumber()
169+
para := make(map[string]interface{})
170+
err = decoder.Decode(&para)
167171
if err != nil {
168172
log.Error(err)
169-
return nil, err
173+
panic(err)
170174
}
171175

176+
log.Info(para["result"])
177+
178+
var resultBuf []byte
172179
var accountInfo = &user_proto.AccountInfoData{}
180+
if para["result"] != nil {
181+
resultBuf, err = json.Marshal(para["result"])
182+
//resultBuf, err := json.Marshal(commonRet.Result)
183+
if err != nil {
184+
log.Error(err)
185+
return nil, err
186+
}
187+
173188
err = json.Unmarshal(resultBuf, accountInfo)
174189
if err != nil {
175190
log.Error(err)
176191
return nil, err
177192
}
178193

179194
return accountInfo, nil
195+
} else {
196+
return accountInfo, nil
197+
}
180198
}
181199

182200
// QueryObject get Object

0 commit comments

Comments
 (0)