GO 解析json 字符串

不羁的心 提交于 2020-03-09 21:45:48
goframe 框架
// 数据格式 [{"title":"首页", "ur l":"asdasdasdas", "image_url":"fdgfdgfgfc","list_order":1},{"title":"订单", "url":"asdasdasdas", "image_url":"fdgfdgfgfc","list_order":2},{"title":"个人中心", "url":"asdasdasdas", "image_url":"fdgfdgfgfc","list_order":3}]    var arr g.Array
    images := r.GetString("images")
    err = json.Unmarshal([]byte(images), &arr)
    if err != nil{
        return err
    }
    imgList := g.List{}
    for _, v := range arr{
        rpcId, err := genId.GetId()
        if err != nil{
            return nil
        }
        image := gconv.Map(v)
        checkRes := checkImages(image)
        if checkRes != nil{
            return checkRes
        }
        imgList = append(imgList, g.Map{
            "id": rpcId.NextId,
            "slider_id": sliderId,
            "title": image["title"],
            "list_order": image["list_order"],
            "url": image["url"],
            "image_url": image["image_url"],
            "created_at": gtime.Now().Unix(),
        })
    }
    _, err = tx.Table(slider_image.Table).Data(imgList).Save()
    if err != nil{
        return err
    }
    return nil

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!