-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(chaoxing):fix JSON parsing error in content
field
#5877
Conversation
Thanks for opening this pull request! Please check out our contributing guidelines. |
drivers/chaoxing/types.go
Outdated
func (ios *int_str) UnmarshalJSON(data []byte) error { | ||
// 解析为int | ||
var intValue int | ||
if err := json.Unmarshal(data, &intValue); err == nil { | ||
*ios = int_str(intValue) | ||
return nil | ||
} | ||
// 解析string再转int | ||
var strValue string | ||
if err := json.Unmarshal(data, &strValue); err == nil { | ||
intValue, err := strconv.Atoi(strValue) | ||
if err != nil { | ||
return fmt.Errorf("json: cannot unmarshal data into Go struct field .list.content._ of type int_string") | ||
} | ||
*ios = int_str(intValue) | ||
} | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没必要这样转,json字符串和数字就双引号的区别,删除双引号就是数字
intValue, err := strconv.Atoi(string(bytes.Trim(data , "\"")))
if err != nil {
return err
}
*ios = int_str(intValue)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
谢谢您的指正,已经改进
Congrats on merging your first pull request! We here at behavior bot are proud of you! |
哥们还是不要叫计算机菜鸟了! formidable opponent! |
* fix(chaoxing):fix JSON parsing error in `content` field * fix(chaoxing): optimizing `UnmarshalJSON` implementation * fix(chaoxing): use `objectID` when is empty
* fix(chaoxing):fix JSON parsing error in `content` field * fix(chaoxing): optimizing `UnmarshalJSON` implementation * fix(chaoxing): use `objectID` when is empty
手机端超星上传小组云盘和网页端上传的文件在获取文件信息(
pc/resource/getResourceList&recType=2
)时返回的 json 格式不同,size
和puid
字段可能是 string 也可能是 int。用自定义数据类型
int_str
和unmarshaler
接口来解决此问题。