尝试打印哈希时获取错误“不是ARRAY引用”。不知道我哪里错了。有没有办法以这样的方式打印解码的json,这样可以更容易地识别哈希元素?
use JSON qw( decode_json );
my $owm_json= <<'__EOI__';
{"cod":"200","city":{"id":"4270936","name":"Bazine","coord":{"lon":-99.6935,"lat":38.4421},"country":"United States of America","population":0},"cnt":65,"model":"OWM","list":{"0":{"dt":1390615200,"main":{"temp":39.63,"temp_min":39.69,"temp_max":43.7,"pressure":950.95,"humidity":62.4},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"clouds":{"all":73,"low":0,"middle":6,"high":72},"wind":{"speed":15.98,"deg":269,"gust":13.8},"sys":{"pod":"n"}},"1":{"dt":1390626000,"main":{"temp":40.89,"temp_min":39.69,"temp_max":43.7,"pressure":951.79,"humidity":54.7},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"clouds":{"all":82,"low":0,"middle":3,"high":82},"wind":{"speed":16.78,"deg":290,"gust":16.5},"sys":{"pod":"n"}},"2":{"dt":1390636800,"main":{"temp":41.45,"temp_min":40.91,"temp_max":41.72,"pressure":952.77,"humidity":47.7},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03n"}],"clouds":{"all":35,"low":0,"middle":0,"high":35},"wind":{"speed":16.63,"deg":314,"gust":18.7},"sys":{"pod":"n"}},"3":{"dt":1390647600,"main":{"temp":39.81,"temp_min":39.83,"temp_max":41.72,"pressure":953.7,"humidity":48.9},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03n"}],"clouds":{"all":32,"low":0,"middle":0,"high":32},"wind":{"speed":14.13,"deg":314,"gust":16.5},"sys":{"pod":"n"}},"4":{"dt":1390658400,"main":{"temp":40.51,"temp_min":38.5,"temp_max":40.53,"pressure":954.95,"humidity":50.3},"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],"clouds":{"all":23,"low":0,"middle":0,"high":23},"wind":{"speed":12.79,"deg":318,"gust":13.9},"sys":{"pod":"d"}},"5":{"dt":1390669200,"main":{"temp":51.67,"temp_min":38.5,"temp_max":51.66,"pressure":955.03,"humidity":44.3},"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],"clouds":{"all":18,"low":0,"middle":0,"high":18},"wind":{"speed":14.49,"deg":348,"gust":10.1},"sys":{"pod":"d"}},"6":{"dt":1390680000,"main":{"temp":54.99,"temp_min":51.75,"temp_max":55,"pressure":952.14,"humidity":40.3},"weather":[{"id":800,"main":"Clear","description":"sky is clear","icon":"01d"}],"clouds":{"all":1,"low":0,"middle":0,"high":1},"wind":{"speed":8.45,"deg":326,"gust":7.5},"sys":{"pod":"d"}},"7":{"dt":1390690800,"main":{"temp":46.15,"temp_min":45.82,"temp_max":55.35,"pressure":950.37,"humidity":53},"weather":[{"id":800,"main":"Clear","description":"sky is clear","icon":"02d"}],"clouds":{"all":10,"low":0,"middle":0,"high":10},"wind":{"speed":5.05,"deg":233,"gust":3.3},"sys":{"pod":"d"}},"8":{"dt":1390701600,"main":{"temp":45.1,"temp_min":45.1,"temp_max":47.71,"pressure":948.92,"humidity":53.8},"weather":[{"id":800,"main":"Clear","description":"sky is clear","icon":"01n"}],"clouds":{"all":0,"low":0,"middle":0,"high":0},"wind":{"speed":12.77,"deg":235,"gust":9.8},"sys":{"pod":"n"}},"9":{"dt":1390712400,"main":{"temp":43.43,"temp_min":43.41,"temp_max":47.71,"pressure":947.31,"humidity":56.4},"weather":[{"id":800,"main":"Clear","description":"sky is clear","icon":"01n"}],"clouds":{"all":0,"low":0,"middle":0,"high":0},"wind":{"speed":14.21,"deg":243,"gust":12.5},"sys":{"pod":"n"}},"10":{"dt":1390723200,"main":{"temp":41.38,"temp_min":41.43,"temp_max":43.41,"pressure":946.75,"humidity":59},"weather":[{"id":800,"main":"Clear","description":"sky is clear","icon":"01n"}],"clouds":{"all":0,"low":0,"middle":0,"high":0},"wind":{"speed":14.52,"deg":257,"gust":13.9},"sys":{"pod":"n"}},"11":{"dt":1390734000,"main":{"temp":39.83,"temp_min":39.4,"temp_max":43.41,"pressure":946.52,"humidity":56.8},"weather":[{"id":800,"main":"Clear","description":"sky is clear","icon":"01n"}],"clouds":{"all":0,"low":0,"middle":0,"high":0},"wind":{"speed":11.66,"deg":321,"gust":11.7},"sys":{"pod":"n"}},"12":{"dt":1390744800,"main":{"temp":41.22,"temp_min":39.16,"temp_max":41.25,"pressure":947.87,"humidity":50.3},"weather":[{"id":800,"main":"Clear","description":"sky is clear","icon":"01d"}],"clouds":{"all":0,"low":0,"middle":0,"high":0},"wind":{"speed":9.37,"deg":327,"gust":8},"sys":{"pod":"d"}},"13":{"dt":1390755600,"main":{"temp":51.73,"temp_min":39.16,"temp_max":51.76,"pressure":947.62,"humidity":34.6},"weather":[{"id":800,"main":"Clear","description":"sky is clear","icon":"01d"}],"clouds":{"all":0,"low":0,"middle":0,"high":0},"wind":{"speed":11.36,"deg":346,"gust":7.7},"sys":{"pod":"d"}},"14":{"dt":1390766400,"main":{"temp":53.58,"temp_min":51.85,"temp_max":53.64,"pressure":945.56,"humidity":30.5},"weather":[{"id":800,"main":"Clear","description":"sky is clear","icon":"01d"}],"clouds":{"all":0,"low":0,"middle":0,"high":0},"wind":{"speed":12.48,"deg":345,"gust":8.4},"sys":{"pod":"d"}},"15":{"dt":1390777200,"main":{"temp":46.44,"temp_min":46.4,"temp_max":53.64,"pressure":948.09,"humidity":39},"weather":[{"id":800,"main":"Clear","description":"sky is clear","icon":"01d"}],"clouds":{"all":0,"low":0,"middle":0,"high":0},"wind":{"speed":11.69,"deg":14,"gust":10.1},"sys":{"pod":"d"}},"16":{"dt":1390788000,"main":{"temp":37.4,"temp_min":37.36,"temp_max":46.4,"pressure":954.84,"humidity":54.9},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13n"}],"clouds":{"all":66,"low":66,"middle":19,"high":0},"wind":{"speed":24.34,"deg":17,"gust":15.1},"snow":{"3h":0.12},"sys":{"pod":"n"}},"17":{"dt":1390798800,"main":{"temp":27.99,"temp_min":27.97,"temp_max":46.4,"pressure":959.47,"humidity":33.9},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13n"}],"clouds":{"all":80,"low":63,"middle":57,"high":0},"wind":{"speed":21.56,"deg":10,"gust":12.7},"snow":{"3h":0.1},"sys":{"pod":"n"}},"18":{"dt":1390809600,"main":{"temp":22.53,"temp_min":22.55,"temp_max":27.95,"pressure":961.66,"humidity":27.8},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"clouds":{"all":99,"low":8,"middle":99,"high":0},"wind":{"speed":17.02,"deg":2,"gust":10.3},"sys":{"pod":"n"}},"19":{"dt":1390820400,"main":{"temp":20.61,"temp_min":20.57,"temp_max":27.95,"pressure":962.45,"humidity":23.1},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"clouds":{"all":100,"low":8,"middle":100,"high":0},"wind":{"speed":13.67,"deg":2,"gust":8.5},"sys":{"pod":"n"}},"20":{"dt":1390831200,"main":{"temp":20.32,"temp_min":20.01,"temp_max":20.55,"pressure":964.61,"humidity":21.3},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],"clouds":{"all":100,"low":44,"middle":100,"high":0},"wind":{"speed":10.04,"deg":14,"gust":5.9},"sys":{"pod":"d"}},"21":{"dt":1390842000,"main":{"temp":23.4,"temp_min":20.01,"temp_max":23.4,"pressure":965.27,"humidity":17.9},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],"clouds":{"all":100,"low":52,"middle":100,"high":0},"wind":{"speed":6.83,"deg":6,"gust":4.2},"sys":{"pod":"d"}},"22":{"dt":1390852800,"main":{"temp":25.48,"temp_min":23.4,"temp_max":25.54,"pressure":963.17,"humidity":17.4},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],"clouds":{"all":100,"low":44,"middle":100,"high":0},"wind":{"speed":4.73,"deg":346,"gust":3.5},"sys":{"pod":"d"}},"23":{"dt":1390863600,"main":{"temp":24.8,"temp_min":23.4,"temp_max":25.63,"pressure":963.34,"humidity":19.6},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],"clouds":{"all":100,"low":39,"middle":100,"high":0},"wind":{"speed":3.67,"deg":40,"gust":2},"sys":{"pod":"d"}},"24":{"dt":1390874400,"main":{"temp":23.34,"temp_min":23.36,"temp_max":24.73,"pressure":964.88,"humidity":21},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"clouds":{"all":100,"low":3,"middle":100,"high":0},"wind":{"speed":5.23,"deg":115,"gust":2.9},"sys":{"pod":"n"}},"25":{"dt":1390885200,"main":{"temp":20.53,"temp_min":20.53,"temp_max":24.73,"pressure":965.28,"humidity":25.9},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"clouds":{"all":96,"low":2,"middle":96,"high":0},"wind":{"speed":5.66,"deg":138,"gust":3.8},"sys":{"pod":"n"}},"26":{"dt":1390896000,"main":{"temp":18.52,"temp_min":18.54,"temp_max":20.08,"pressure":964.39,"humidity":41.1},"weather":[{"id":800,"main":"Clear","description":"sky is clear","icon":"01n"}],"clouds":{"all":1,"low":0,"middle":1,"high":0},"wind":{"speed":6.39,"deg":171,"gust":4.6},"sys":{"pod":"n"}},"27":{"dt":1390906800,"main":{"temp":18.68,"temp_min":18.41,"temp_max":20.08,"pressure":963.68,"humidity":67.5},"weather":[{"id":800,"main":"Clear","description":"sky is clear","icon":"02n"}],"clouds":{"all":4,"low":0,"middle":4,"high":0},"wind":{"speed":6.89,"deg":201,"gust":5},"sys":{"pod":"n"}},"28":{"dt":1390917600,"main":{"temp":23.43,"temp_min":18.88,"temp_max":23.41,"pressure":964.4,"humidity":75.5},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"clouds":{"all":37,"low":7,"middle":33,"high":0},"wind":{"speed":10.26,"deg":220,"gust":7.5},"sys":{"pod":"d"}},"29":{"dt":1390928400,"main":{"temp":33.31,"temp_min":18.88,"temp_max":33.31,"pressure":963.48,"humidity":41.3},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"clouds":{"all":45,"low":29,"middle":17,"high":0},"wind":{"speed":12.1,"deg":242,"gust":6.9},"sys":{"pod":"d"}},"30":{"dt":1390939200,"main":{"temp":37.06,"temp_min":33.48,"temp_max":37.02,"pressure":960.5,"humidity":31.6},"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],"clouds":{"all":12,"low":12,"middle":0,"high":0},"wind":{"speed":7.17,"deg":284,"gust":5},"sys":{"pod":"d"}},"31":{"dt":1390950000,"main":{"temp":27,"temp_min":26.96,"temp_max":37.02,"pressure":961.66,"humidity":53.9},"weather":[{"id":800,"main":"Clear","description":"sky is clear","icon":"02d"}],"clouds":{"all":6,"low":6,"middle":0,"high":0},"wind":{"speed":9.68,"deg":38,"gust":6.2},"sys":{"pod":"d"}},"32":{"dt":1390960800,"main":{"temp":17.92,"temp_min":18,"temp_max":26.92,"pressure":962.49,"humidity":78.9},"weather":[{"id":800,"main":"Clear","description":"sky is clear","icon":"01n"}],"clouds":{"all":0,"low":0,"middle":0,"high":0},"wind":{"speed":9.59,"deg":66,"gust":6.8},"sys":{"pod":"n"}},"33":{"dt":1390971600,"main":{"temp":17.22,"temp_min":16.92,"temp_max":26.92,"pressure":961.43,"humidity":73.3},"weather":[{"id":800,"main":"Clear","description":"sky is clear","icon":"01n"}],"clouds":{"all":0,"low":0,"middle":0,"high":0},"wind":{"speed":6.13,"deg":101,"gust":3.9},"sys":{"pod":"n"}},"34":{"dt":1390982400,"main":{"temp":20.05,"temp_min":17.28,"temp_max":19.99,"pressure":957.98,"humidity":60.7},"weather":[{"id":800,"main":"Clear","description":"sky is clear","icon":"01n"}],"clouds":{"all":0,"low":0,"middle":0,"high":0},"wind":{"speed":7.78,"deg":161,"gust":5.9},"sys":{"pod":"n"}},"35":{"dt":1390993200,"main":{"temp":22.8,"temp_min":17.28,"temp_max":22.8,"pressure":954.89,"humidity":44.4},"weather":[{"id":800,"main":"Clear","description":"sky is clear","icon":"01n"}],"clouds":{"all":0,"low":0,"middle":0,"high":0},"wind":{"speed":11.58,"deg":196,"gust":10.5},"sys":{"pod":"n"}},"36":{"dt":1391004000,"main":{"temp":27.03,"temp_min":22.8,"temp_max":27.01,"pressure":952.39,"humidity":37.7},"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],"clouds":{"all":15,"low":0,"middle":0,"high":15},"wind":{"speed":16.48,"deg":206,"gust":15.1},"sys":{"pod":"d"}},"37":{"dt":1391014800,"main":{"temp":41.68,"temp_min":22.8,"temp_max":41.7,"pressure":950.31,"humidity":27.1},"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],"clouds":{"all":21,"low":0,"middle":0,"high":21},"wind":{"speed":19.14,"deg":217,"gust":12.7},"sys":{"pod":"d"}},"38":{"dt":1391025600,"main":{"temp":48.13,"temp_min":41.86,"temp_max":48.07,"pressure":946.47,"humidity":28.8},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"clouds":{"all":27,"low":0,"middle":0,"high":27},"wind":{"speed":15.62,"deg":221,"gust":9.6},"sys":{"pod":"d"}},"39":{"dt":1391036400,"main":{"temp":39.42,"temp_min":39.47,"temp_max":48.18,"pressure":945.8,"humidity":46.6},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"clouds":{"all":33,"low":0,"middle":0,"high":33},"wind":{"speed":9.76,"deg":217,"gust":7},"sys":{"pod":"d"}},"40":{"dt":1391047200,"main":{"temp":36.48,"temp_min":36.45,"temp_max":39.47,"pressure":944.9,"humidity":53.5},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03n"}],"clouds":{"all":44,"low":0,"middle":0,"high":44},"wind":{"speed":11.19,"deg":220,"gust":7.4},"sys":{"pod":"n"}},"41":{"dt":1391058000,"main":{"temp":35.64,"temp_min":35.65,"temp_max":39.47,"pressure":943.31,"humidity":52.6},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03n"}],"clouds":{"all":42,"low":0,"middle":0,"high":42},"wind":{"speed":9.31,"deg":230,"gust":6.4},"sys":{"pod":"n"}},"42":{"dt":1391068800,"main":{"temp":34.54,"temp_min":34.57,"temp_max":35.65,"pressure":942.67,"humidity":53.4},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"clouds":{"all":64,"low":0,"middle":0,"high":64},"wind":{"speed":9.03,"deg":252,"gust":6.1},"sys":{"pod":"n"}},"43":{"dt":1391079600,"main":{"temp":35.6,"temp_min":34.57,"temp_max":35.87,"pressure":943.94,"humidity":53.4},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"clouds":{"all":72,"low":0,"middle":0,"high":72},"wind":{"speed":9.91,"deg":328,"gust":6.7},"sys":{"pod":"n"}},"44":{"dt":1391090400,"main":{"temp":26.78,"temp_min":26.78,"temp_max":35.56,"pressure":947.55,"humidity":77.2},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"clouds":{"all":79,"low":0,"middle":0,"high":79},"wind":{"speed":18.3,"deg":24,"gust":12},"sys":{"pod":"d"}},"45":{"dt":1391101200,"main":{"temp":33.49,"temp_min":26.78,"temp_max":35.56,"pressure":949.78,"humidity":58},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"clouds":{"all":79,"low":0,"middle":18,"high":72},"wind":{"speed":8.21,"deg":45,"gust":5},"sys":{"pod":"d"}},"46":{"dt":1391112000,"main":{"temp":38.25,"temp_min":33.66,"temp_max":38.21,"pressure":948.38,"humidity":50.6},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],"clouds":{"all":87,"low":0,"middle":2,"high":86},"wind":{"speed":6.8,"deg":85,"gust":3.5},"sys":{"pod":"d"}},"47":{"dt":1391122800,"main":{"temp":34.84,"temp_min":33.66,"temp_max":38.39,"pressure":948.29,"humidity":58.7},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],"clouds":{"all":90,"low":0,"middle":1,"high":90},"wind":{"speed":5.96,"deg":99,"gust":3.6},"sys":{"pod":"d"}},"48":{"dt":1391133600,"main":{"temp":31.03,"temp_min":31.05,"temp_max":34.72,"pressure":948.27,"humidity":67.5},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"clouds":{"all":79,"low":0,"middle":0,"high":79},"wind":{"speed":8.53,"deg":126,"gust":6},"sys":{"pod":"n"}},"49":{"dt":1391144400,"main":{"temp":27.75,"temp_min":27.77,"temp_max":34.72,"pressure":946.79,"humidity":75.4},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"clouds":{"all":68,"low":0,"middle":0,"high":68},"wind":{"speed":8.86,"deg":135,"gust":6.6},"sys":{"pod":"n"}},"50":{"dt":1391155200,"main":{"temp":26.46,"temp_min":26.49,"temp_max":27.77,"pressure":944.93,"humidity":77.7},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"clouds":{"all":54,"low":0,"middle":1,"high":54},"wind":{"speed":7.32,"deg":126,"gust":5.3},"sys":{"pod":"n"}},"51":{"dt":1391166000,"main":{"temp":26.51,"temp_min":26.47,"temp_max":27.77,"pressure":943.57,"humidity":76.8},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"clouds":{"all":71,"low":0,"middle":12,"high":71},"wind":{"speed":8.25,"deg":121,"gust":6.4},"sys":{"pod":"n"}},"52":{"dt":1391176800,"main":{"temp":28.17,"temp_min":26.35,"temp_max":28.13,"pressure":944.18,"humidity":72.3},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],"clouds":{"all":92,"low":1,"middle":57,"high":92},"wind":{"speed":5.34,"deg":98,"gust":3},"sys":{"pod":"d"}},"53":{"dt":1391187600,"main":{"temp":37.06,"temp_min":26.35,"temp_max":37.13,"pressure":943.56,"humidity":57.3},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"clouds":{"all":62,"low":8,"middle":29,"high":57},"wind":{"speed":4.06,"deg":69,"gust":1.8},"sys":{"pod":"d"}},"54":{"dt":1391198400,"main":{"temp":43.34,"temp_min":37.15,"temp_max":43.36,"pressure":942.37,"humidity":52.1},"weather":[{"id":800,"main":"Clear","description":"sky is clear","icon":"02d"}],"clouds":{"all":7,"low":0,"middle":0,"high":6},"wind":{"speed":5.03,"deg":5,"gust":2.6},"sys":{"pod":"d"}},"55":{"dt":1391209200,"main":{"temp":38.35,"temp_min":37.15,"temp_max":43.99,"pressure":944.19,"humidity":60.7},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"clouds":{"all":38,"low":0,"middle":1,"high":38},"wind":{"speed":9.05,"deg":30,"gust":6.4},"sys":{"pod":"d"}},"56":{"dt":1391220000,"main":{"temp":33.87,"temp_min":33.89,"temp_max":38.34,"pressure":947.09,"humidity":66.8},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"clouds":{"all":90,"low":0,"middle":44,"high":90},"wind":{"speed":8.25,"deg":34,"gust":6.3},"sys":{"pod":"n"}},"57":{"dt":1391230800,"main":{"temp":32.59,"temp_min":32.14,"temp_max":38.34,"pressure":947.46,"humidity":66.6},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"clouds":{"all":90,"low":0,"middle":60,"high":89},"wind":{"speed":9.09,"deg":23,"gust":6.7},"sys":{"pod":"n"}},"58":{"dt":1391241600,"main":{"temp":30.47,"temp_min":30.43,"temp_max":32.81,"pressure":947.9,"humidity":69.8},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"clouds":{"all":96,"low":2,"middle":96,"high":52},"wind":{"speed":13.09,"deg":21,"gust":9.2},"sys":{"pod":"n"}},"59":{"dt":1391252400,"main":{"temp":27.23,"temp_min":27.09,"temp_max":32.81,"pressure":948.71,"humidity":81.7},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"clouds":{"all":85,"low":1,"middle":85,"high":31},"wind":{"speed":10.63,"deg":35,"gust":9.4},"sys":{"pod":"n"}},"60":{"dt":1391263200,"main":{"temp":26.02,"temp_min":26.06,"temp_max":27.59,"pressure":951.34,"humidity":93.6},"weather":[{"id":601,"main":"Snow","description":"snow","icon":"13d"}],"clouds":{"all":99,"low":67,"middle":99,"high":80},"wind":{"speed":9.85,"deg":37,"gust":6.8},"snow":{"3h":3.7},"sys":{"pod":"d"}},"61":{"dt":1391274000,"main":{"temp":27.5,"temp_min":26.04,"temp_max":27.54,"pressure":952.46,"humidity":87.2},"weather":[{"id":601,"main":"Snow","description":"snow","icon":"13d"}],"clouds":{"all":100,"low":82,"middle":99,"high":89},"wind":{"speed":7.8,"deg":42,"gust":4.6},"snow":{"3h":6.1},"sys":{"pod":"d"}},"62":{"dt":1391284800,"main":{"temp":29.44,"temp_min":27.77,"temp_max":29.46,"pressure":951.54,"humidity":82.5},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13d"}],"clouds":{"all":100,"low":99,"middle":31,"high":49},"wind":{"speed":5.94,"deg":36,"gust":3.2},"snow":{"3h":0.1},"sys":{"pod":"d"}},"63":{"dt":1391295600,"main":{"temp":22.62,"temp_min":22.62,"temp_max":29.64,"pressure":952.76,"humidity":92.3},"weather":[{"id":601,"main":"Snow","description":"snow","icon":"13d"}],"clouds":{"all":89,"low":88,"middle":16,"high":25},"wind":{"speed":2.29,"deg":93,"gust":1.5},"snow":{"3h":6.2},"sys":{"pod":"d"}},"model":"gfs"}}";
__EOI__
my $decoded = decode_json($owm_json);
print $decoded->{list}[0]->{weather}[0]->{description};
答案 0 :(得分:4)
您的字符串$owm_json
不是有效的Perl字符串。从短片段:
"{"cod":"200","city":{"id":"4270936","name":
这应该是:
"{\"cod\":\"200\",\"city\":{\"id\":\"4270936\",\"name\":
您需要转义内部引号。尝试将use strict
放在脚本的开头,应该已经发现了这个错误。
从评论中更新:
查看您的JSON数据,您对descpiption字段的访问权限不正确。以下是您尝试在示例中显示的部分:
"list" : {
"0" : {
"weather" : [{
"id" : 803,
"main" : "Clouds",
"description" : "broken clouds",
"icon" : "04n"
}
],
请注意,在“list”之后你有“0”,而不是使用[]
个字符的数组引用。在您的脚本中,在{list}
使用{0}
而不是[0]
后,这应该可以解决您的问题:
print $decoded->{list}{0}{weather}[0]{description};
答案 1 :(得分:2)
list
的值是一个哈希值(...,"list":{"0":{...},...
),但您尝试取消引用的是->[0]
,这是一个数组解除引用。
你想:
$decoded->{list}{0}{weather}[0]{description}
而不是
$decoded->{list}[0]{weather}[0]{description}