序列化与反序列化 未知结构的数据 Any interface类型

小结:

1、

type Any interface {
}
v1 := new(Any)

err = json.Unmarshal([]byte(bs1), &v1)
V interface{}
resp.V = v1
 
 
 

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package presentationLayer
 
import (
    "TestApp/SRE"
    service "TestApp/internal/service"
    "encoding/json"
    "io"
 
    ghttp "github.com/go-kratos/kratos/v2/transport/http"
 
    "TestApp/utils"
    "bytes"
    "crypto/md5"
    "fmt"
    "net/http"
    "strings"
    "time"
)
 
func GeoAddress(sreCli *SRE.SREClient, srv *service.GoodsService, ctx ghttp.Context) error {
    bs, err := io.ReadAll(ctx.Request().Body)
    if err != nil {
        sreCli.ApiAlertByQyWxApp(1, bs, nil, ctx.Header())
        return err
    }
    app_key := "app_key"
    version := "1.0"
    timestamp_int := int(time.Now().Unix())
    timestamp := utils.Int2Str(timestamp_int)
    nonce_str := "nonce_str"
    appSecret := "appSecret"
    l := []string{
        utils.ConcatStr("app_key=", app_key),
        utils.ConcatStr("nonce_str=", nonce_str),
        utils.ConcatStr("timestamp=", timestamp),
        utils.ConcatStr("version=", version),
        appSecret,
    }
    sign := func() string {
        s1 := strings.Join(l, "&")
        b := md5.Sum([]byte(s1))
        return strings.ToLower(fmt.Sprintf("%x", b))
    }()
 
    endpoint := "https://api.endpoint/areas/get_list"
    reader := func() *bytes.Reader {
        t := map[string]interface{}{
            "app_key":   app_key,
            "version":   version,
            "timestamp": timestamp_int,
            "nonce_str": nonce_str,
            "sign":      sign,
        }
        p, _ := json.Marshal(t)
        return bytes.NewReader(p)
    }()
    r, err := http.NewRequest("POST", endpoint, reader)
    if err != nil {
        // TODO
    }
    r.Header.Set("Content-Type", "application/json")
    client := &http.Client{}
    res, err := client.Do(r)
    if err != nil {
        // TODO
    }
    if res.StatusCode != 200 {
    }
    defer res.Body.Close()
    bs1, err := io.ReadAll(res.Body)
    if err != nil {
        // TODO
    }
 
    type Any interface {
    }
    v1 := new(Any)
 
    err = json.Unmarshal([]byte(bs1), &v1)
    if err != nil {
        // TODO
    }
 
    type R struct {
        CommonResp
        V interface{}
    }
    resp := R{}
    resp.Code = 0
    resp.V = v1
    sreCli.ApiAlertByQyWxApp(0, nil, resp, ctx.Header())
    return ctx.Result(200, resp)
}

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{
    "Code": 0,
    "Msg": "",
    "DevMsg": "",
    "V": {
        "code": 200,
        "data": [
            {
                "area_id": 1,
                "area_name": "北京市",
                "children": [
                    {
                        "area_id": 2,
                        "area_name": "东城区",
                        "children": [
                            {
                                "area_id": 3,
                                "area_name": "东华门街道",
                                "id": 110101001,
                                "pid": 110101,
                                "status": 1
                            },
                            {
                                "area_id": 4,
                                "area_name": "景山街道",
                                "id": 110101002,
                                "pid": 110101,
                                "status": 1
                            },

  

  

 

posted @   papering  阅读(73)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
历史上的今天:
2021-05-13 公共参数
2021-05-13 日期格式 基本规则
2021-05-13 React 代码共享最佳实践方式
2021-05-13 单元测试用例编写流程 编写单元测试代码遵守BCDE原则 AIR原则
2019-05-13 DevOps时代的软件过程改进探讨 杨振涛 云加社区 今天 作者:杨振涛,腾讯云TVP 本文从Jenkins,DevOps,云原生等视角探讨了软件过程改进在各个时代的挑战和价值,重新审视了SPI在软件开发和交付的效率和质量提升方面的意义
2019-05-13 电竞大数据平台 FunData 的系统架构演进
2019-05-13 数据平台 分层
点击右上角即可分享
微信分享提示