jshn - 如何解析 json 包

Mar*_*arz 3 parsing json filtering openwrt

我想知道如何在 openwrt 上轻松解析 json?

我有 jhsn 来解析 json,这是我的程序(.sh 脚本):

#download weather
wget "api.openweathermap.org/data/2.5/weather?id=2172797&appid=44db6a862fba0b067b1930da0d769e98"
#set variable wit json data
$weather=`cat weather?`
jshn -r "$weather"
Run Code Online (Sandbox Code Playgroud)

最后它显示:

json_init;
json_add_object 'coord';
json_add_double 'lon' 18.650000;
json_add_double 'lat' 50.300000;
json_close_object;
json_add_array 'weather';
json_add_object '0';
json_add_int 'id' 701;
json_add_string 'main' 'Mist';
json_add_string 'description' 'mist';
json_add_string 'icon' '50n';
json_close_object;
json_close_array;
json_add_string 'base' 'cmc stations';
json_add_object 'main';
json_add_double 'temp' 262.900000;
json_add_int 'pressure' 1033;
json_add_int 'humidity' 92;
json_add_double 'temp_min' 261.150000;
json_add_double 'temp_max' 263.750000;
json_close_object;
json_add_object 'wind';
json_add_double 'speed' 3.100000;
json_add_int 'deg' 140;
json_close_object;
json_add_object 'snow';
json_close_object;
json_add_object 'clouds';
json_add_int 'all' 0;
json_close_object;
json_add_int 'dt' 1453490267;
json_add_object 'sys';
json_add_int 'type' 3;
json_add_int 'id' 5356;
json_add_double 'message' 0.010000;
json_add_string 'country' 'PL';
json_add_int 'sunrise' 1453444351;
json_add_int 'sunset' 1453476124;
json_close_object;
json_add_int 'id' 7530857;
json_add_string 'name' 'Gliwice';
json_add_int 'cod' 200;
Run Code Online (Sandbox Code Playgroud)

我怎样才能过滤它并只得到一个值?例如速度值:3.100000 与 jshn 或其他脚本等?

Mar*_*arz 5

以下脚本做我需要的

#!/bin/sh

. /usr/share/libubox/jshn.sh

O=$(wget "api.openweathermap.org/data/2.5/weather?id=2172797&appid=44db6a862fba0b067b1930da0d769e98" -O -)

json_load "$O"
json_select wind
json_get_var var1 speed
echo "speed: $var1"
Run Code Online (Sandbox Code Playgroud)

更多信息@ http://eko.one.pl/forum/viewtopic.php?pid=157702#p157702