GO处理一些未知结构的JSON,纠结一个星期了

vus520 · 2017-04-17 14:23:41 · 4021 次点击 · 大约8小时之前 开始浏览    置顶
这是一个创建于 2017-04-17 14:23:41 的主题,其中的信息可能已经有所发展或是发生改变。

这是elasticsearch的返回结构,aggregations中的user、tags、ct等都是不可预知的字段,要如何取出这些结构,并还原成一维map?

{
    "took": 2,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 3,
        "failed": 0
    },
    "hits": {
        "total": 22,
        "max_score": 0,
        "hits": []
    },
    "aggregations": {
        "user": {
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 0,
            "buckets": [
                {
                    "key": "olivere",
                    "doc_count": 16,
                    "tags": {
                        "doc_count_error_upper_bound": 0,
                        "sum_other_doc_count": 0,
                        "buckets": [
                            {
                                "key": "golang",
                                "doc_count": 16,
                                "ct": {
                                    "value": 16
                                }
                            },
                            {
                                "key": "elasticsearch",
                                "doc_count": 7,
                                "ct": {
                                    "value": 7
                                }
                            }
                        ]
                    }
                },
                {
                    "key": "sandrae",
                    "doc_count": 6,
                    "tags": {
                        "doc_count_error_upper_bound": 0,
                        "sum_other_doc_count": 0,
                        "buckets": [
                            {
                                "key": "cycling",
                                "doc_count": 6,
                                "ct": {
                                    "value": 6
                                }
                            },
                            {
                                "key": "sports",
                                "doc_count": 6,
                                "ct": {
                                    "value": 6
                                }
                            }
                        ]
                    }
                }
            ]
        }
    }
}

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

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

4021 次点击  
加入收藏 微博
8 回复  |  直到 2017-04-20 07:12:17
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传