Shell 下使用 jq
解析 JSON,十分方便。
源数据
$ curl ip.dhcp.cn/?json
{
"IP": "134.175.159.160",
"Address": {
"Country": "中国",
"Province": "广东省",
"City": "广州市"
},
"ISP": "电信"
}
$ curl -s ip.dhcp.cn/?json | jq .IP
"134.175.159.160"
$ curl -s ip.dhcp.cn/?json | jq ".Address"
{
"Country": "中国",
"Province": "广东省",
"City": "广州市"
}
$ curl -s ip.dhcp.cn/?json | jq ".Address | length"
3
$ curl -s ip.dhcp.cn/?json | jq .Address.City
"广州市"
$ curl -s ‘ip.dhcp.cn/?json‘ | python -c "import sys, json; print json.load(sys.stdin)[‘IP‘]"
134.175.159.160
原文:https://www.cnblogs.com/watering/p/14382563.html