如何优雅解析http response结构体?

Dear · 2022-03-04 10:48:47 · 1652 次点击 · 大约8小时之前 开始浏览    置顶
这是一个创建于 2022-03-04 10:48:47 的主题,其中的信息可能已经有所发展或是发生改变。

成功了 是 {"resp": {"respCode": "10000","respMsg": "成功","app": {"appId": "xxxxxx"}}}

不成功是 {"resp": {"respCode": "10002","respMsg": "失败","app": “”}}

结构体怎么写,才能兼容接收response的成功和失败


有疑问加站长微信联系(非本文作者)

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

1652 次点击  
加入收藏 微博
4 回复  |  直到 2022-03-12 12:35:49
guosheng1987
guosheng1987 · #1 · 3年之前

type AutoGenerated struct { Resp Resp json:"resp" } type Resp struct { RespCode string json:"respCode" RespMsg string json:"respMsg" App interface{}json:"app" }

Dear
Dear · #2 · 3年之前
guosheng1987guosheng1987 #1 回复

type AutoGenerated struct { Resp Resp `json:"resp"` } type Resp struct { RespCode string `json:"respCode"` RespMsg string `json:"respMsg"` App interface{}`json:"app"` }

然后用map来解析 app里的json? 没有更好的方案?

pluszero1982
pluszero1982 · #3 · 3年之前

json.RawMessage

ddatsh
ddatsh · #4 · 3年之前
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传