2015年11月4日 星期三

JSON in JAVA

1.Make the JSON more beautiful


https://jsonformatter.curiousconcept.com/

2. if we have the JSON content

{"city":{"id":3093133,"name":"Lodz","coord":{"lon":19.466669,"lat":51.75},"country":"PL","population":0},"cod":"200","message":0.0342,"cnt":7,"list":[{"dt":1446631200,"temp":{"day":4.92,"min":-0.39,"max":8.24,"night":-0.39,"eve":6.36,"morn":0},"pressure":1022.08,"humidity":80,"weather":[{"id":800,"main":"Clear","description":"sky is clear","icon":"01d"}],"speed":3.22,"deg":258,"clouds":0},{"dt":1446717600,"temp":{"day":5.21,"min":-1.21,"max":8.19,"night":2.32,"eve":6.73,"morn":-1.21},"pressure":1024.42,"humidity":87,"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"speed":2.01,"deg":106,"clouds":36},{"dt":1446804000,"temp":{"day":4.36,"min":-1.3,"max":7.92,"night":4.97,"eve":7.28,"morn":0.46},"pressure":1024.22,"humidity":86,"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"speed":1.97,"deg":228,"clouds":0,"rain":2.62},{"dt":1446890400,"temp":{"day":11.87,"min":7.09,"max":12.61,"night":11.64,"eve":12.61,"morn":7.09},"pressure":1020.33,"humidity":0,"weather":[{"id":501,"main":"Rain","description":"moderate rain","icon":"10d"}],"speed":3.46,"deg":231,"clouds":94,"rain":5.34},{"dt":1446976800,"temp":{"day":14.08,"min":9.52,"max":14.08,"night":9.52,"eve":13.85,"morn":11.8},"pressure":1013.83,"humidity":0,"weather":[{"id":501,"main":"Rain","description":"moderate rain","icon":"10d"}],"speed":5.22,"deg":226,"clouds":99,"rain":4.43},{"dt":1447063200,"temp":{"day":9.64,"min":5.93,"max":9.64,"night":5.93,"eve":8.59,"morn":8.38},"pressure":1016.45,"humidity":0,"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"speed":8.81,"deg":284,"clouds":51,"rain":2.43},{"dt":1447149600,"temp":{"day":12.77,"min":6.13,"max":14.46,"night":14.46,"eve":14.18,"morn":6.13},"pressure":1005.35,"humidity":0,"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"speed":7.09,"deg":225,"clouds":94,"rain":1.01}]}


we want to get the first day mix temp



JSONObject jsonObject = new JSONObject(weatherJsonStr);
        JSONArray jaLIST=(JSONArray)jsonObject.get("list");
       JSONObject joDay=jaLIST.getJSONObject(0);
        double max=joDay.getJSONObject("temp").getDouble("max");