针对json的查询--alibaba的开源项目jsonq

项目地址:

https://github.com/alibaba/jsonq

示例json

{
    "foo": 1,
    "bar": 2,
    "test": "Hello, world!",
    "baz": 123.1,
    "array": [
        {"foo": 1},
        {"bar": 2},
        {"baz": 3}
    ],
    "subobj": {
        "foo": 1,
        "subarray": [1,2,3],
        "subsubobj": {
            "bar": 2,
            "baz": 3,
            "array": ["hello", "world"]
        }
    },
    "bool": true
}

调用

import (
    "strings"
    "encoding/json"
    "github.com/jmoiron/jsonq"
)

data := map[string]interface{}{}
dec := json.NewDecoder(strings.NewReader(jsonstring))
dec.Decode(&data)
jq := jsonq.NewQuery(data)
posted @ 2017-10-18 15:02  迪克猪  阅读(717)  评论(0编辑  收藏  举报