1. 首页
  2. 主题
  3. Go问与答

内容不固定的json如何解析呀?新手,搜索了集中方法,还是不知道如何搞

123445 · · 2330 次点击
json1 ```json {"time":1575018625572,"code":10006,"msg":"未查询到对应信息"} ``` json2 ```json { "time": 1575018616175, "code": 0, "msg": "成功", "data": { "list": [ { "id": 23638664, "goodsId": "578575659556", "title": "Milk Skin/奶肌牛奶素颜霜 多效保湿护肤遮瑕提亮面霜清新裸妆女", "dtitle": "Milk Skin/奶肌牛奶素颜霜", "originalPrice": 138, "actualPrice": 108, "shopType": 1, "goldSellers": 0, "monthSales": 3660, "twoHoursSales": 2, "dailySales": 12, "commissionType": 3, "desc": "超火素颜霜,美白遮瑕,补水保湿,提亮肤色,一瓶搞定!天然提取物,进口成分,从根部滋润美白!仙女们的懒人大福利!快速打造美丽素颜,无需卸妆烦恼", "couponReceiveNum": 80, "couponLink": "https://uland.taobao.com/quan/detail?sellerId=4164798236&activityId=d360a99fe2664c128db165c9c87c20c2", "couponEndTime": "2019年12月04日 23:59:59", "couponStartTime": "2019年11月28日 00:00:00", "couponPrice": 30, "couponConditions": "31", "activityType": 1, "createTime": "2019年11月28日 16:38:15", "mainPic": "https://img.alicdn.com/imgextra/i1/4164798236/O1CN01X8zWcx2Ai8UChON4v_!!4164798236.jpg", "marketingMainPic": "https://sr.ffquan.cn/relate_pic/o_1dq8vmfdn48j1c08lpj1io51gs7u.jpg", "sellerId": "4164798236", "cid": 2, "discounts": 0.78, "commissionRate": 20.02, "couponTotalNum": 1000, "haitao": 0, "activityStartTime": "", "activityEndTime": "", "shopName": "milkskin奶肌旗舰店", "shopLevel": 9, "descScore": 4.8, "brand": 0, "brandId": 1878088153, "brandName": "", "hotPush": 0, "teamName": "风神联盟", "itemLink": "https://detail.tmall.com/item.htm?id=578575659556", "tchaoshi": 0, "detailPics": "", "dsrScore": 4.8, "dsrPercent": 13.61, "shipScore": 4.8, "shipPercent": 40.83, "serviceScore": 4.8, "servicePercent": 40.63, "subcid": [ 111746 ], "quanMLink": 0, "hzQuanOver": 0, "yunfeixian": 1, "estimateAmount": -1, "tbcid": 50011980 } ], "totalNum": 1, "pageId": "1" } } ``` 会返回上面两种类型的json,我用`map[string]interface{}`解析出来了,但是要访问里面的各个节点就难搞了,不方便使用,里面的数据的类型怎么搞呀?总是类型不对,解析个json类型都要把我搞死了。
![QQ截图20191208114202.png](https://static.studygolang.com/191208/02f4bbcbcc09b75b7e719da2b99c0b8d.png) 怕你看不懂,给你来个截图吧
#6
更多评论
建議把回傳值 bind 到 struct 上, 請 google google 搜尋 golang decode json
#1
data 使用json.rawmessage 可以再次解析
#2

用户登录

没有账号?注册

今日阅读排行

    加载中

一周阅读排行

    加载中