首页 > 代码库 > Json解析tool工具
Json解析tool工具
JsonTools
package com.example.weather_json.tools; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import com.example.weather_json.Entity.Results; import com.example.weather_json.Entity.WeatherData; import com.example.weather_json.Entity.WeatherInfo; public class JsonTools { public static WeatherInfo MyGetJSON(String jsonString) throws JSONException { List<Results> listResults = null; List<WeatherData> listDatas = null; Results results = null; WeatherData weatherData = http://www.mamicode.com/null;>解析对应的json{ "error": 0, "status": "success", "date": "2014-04-28", "results": [ { "currentCity": "合肥", "weather_data": [ { "date": "周一(今天, 实时:22℃)", "dayPictureUrl": "www.baidu.com", "nightPictureUrl": "www.baidu.com", "weather": "多云转晴", "wind": "西北风微风", "temperature": "22 ~ 13℃" }, { "date": "周二", "dayPictureUrl": "www.baidu.com", "nightPictureUrl": "1www.baidu.com", "weather": "多云", "wind": "西北风微风", "temperature": "24 ~ 14℃" }, { "date": "周三", "dayPictureUrl": "www.baidu.com", "nightPictureUrl": "www.baidu.com", "weather": "多云转晴", "wind": "南风微风", "temperature": "26 ~ 14℃" }, { "date": "周四", "dayPictureUrl": "www.baidu.com", "nightPictureUrl": "www.baidu.com", "weather": "晴", "wind": "东南风微风", "temperature": "27 ~ 13℃" } ] } ] }
json对象在花括号中
{ "firstName":"John" , "lastName":"Doe" }
json数组在中括号中{ "employees": [ { "firstName":"John" , "lastName":"Doe" }, { "firstName":"Anna" , "lastName":"Smith" }, { "firstName":"Peter" , "lastName":"Jones" } ] }
在上面的例子中,对象 "employees" 是包含三个对象的数组。每个对象代表一条关于某人(有姓和名)的记录。
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。