相关文章推荐
犯傻的海豚  ·  Next stop Davos! | ...·  4 月前    · 
热情的煎鸡蛋  ·  像Excel一样使用python进行数据分析 ...·  1 年前    · 
闷骚的山羊  ·  flask-apscheduler使用场景 ...·  1 年前    · 
大力的长颈鹿  ·  Python爱好者社区历史文章列表 - ...·  2 年前    · 
礼貌的海龟  ·  Java 比较两个JSONObject ...·  2 年前    · 
Code  ›  Gson获得json数据数组内嵌问题_问答-阿里云开发者社区
date 云计算 gson jsonobject
https://developer.aliyun.com/ask/86797
痴情的高山
1 年前
产品 解决方案 文档与社区 权益中心 定价 云市场 合作伙伴 支持与服务 了解阿里云
售前咨询
95187-1
在线服务
售后咨询
4008013260
在线服务
其他服务
我要建议
我要投诉
体验反馈
体验反馈
更多联系方式
备案 控制台 登录/注册
开发者社区
首页
探索云世界
探索云世界
云上快速入门,热门云上应用快速查找
了解更多
问产品
动手实践
考认证
TIANCHI大赛
活动广场
活动广场
丰富的线上&线下活动,深入探索云世界
任务中心
做任务,得社区积分和周边
高校计划
让每位学生受益于普惠算力
训练营
资深技术专家手把手带教
话题
畅聊无限,分享你的技术见解
开发者评测
最真实的开发者用云体验
乘风者计划
让创作激发创新
阿里云MVP
遇见技术追梦人
直播
技术交流,直击现场
下载
下载
海量开发者使用工具、手册,免费下载
镜像站
极速、全面、稳定、安全的开源镜像
技术资料
开发手册、白皮书、案例集等实战精华
插件
为开发者定制的Chrome浏览器插件
探索云世界
新手上云 云上应用构建 云上数据管理 云上探索人工智能
云计算 弹性计算 无影 存储 网络 倚天
云原生 容器 serverless 中间件 微服务 可观测 消息队列
数据库 关系型数据库 NoSQL数据库 数据仓库 数据管理工具 PolarDB开源 向量数据库

热门

Modelscope模型即服务 弹性计算 云原生 数据库 物联网 云效DevOps 龙蜥操作系统 平头哥 钉钉开放平台
大数据 大数据计算 实时数仓Hologres 实时计算Flink E-MapReduce DataWorks Elasticsearch 机器学习平台PAI 智能搜索推荐
人工智能 机器学习平台PAI 视觉智能开放平台 智能语音交互 自然语言处理 多模态模型 pythonsdk 通用模型
开发与运维 云效DevOps 钉钉宜搭 支持服务 镜像站 码上公益
开发者社区 >

{
"resultcode": "200",
"reason": "successed!",
"result": {
"sk": {
"temp": "24",
"wind_direction": "西风",
"wind_strength": "2级",
"humidity": "64%",
"time": "17:38"
},
"today": {
"temperature": "19℃~25℃",
"weather": "阴转小雨-中雨",
"weather_id": {
"fa": "02",
"fb": "21"
},
"wind": "旋转风微风",
"week": "星期二",
"city": "绵阳",
"date_y": "2015年09月15日",
"dressing_index": "舒适",
"dressing_advice": "建议着长袖T恤、衬衫加单裤等服装。年老体弱者宜着针织长袖衬衫、马甲和长裤。",
"uv_index": "最弱",
"comfort_index": "",
"wash_index": "不宜",
"travel_index": "较适宜",
"exercise_index": "较适宜",
"drying_index": ""
},
"future": [
{
"temperature": "19℃~25℃",
"weather": "阴转小雨-中雨",
"weather_id": {
"fa": "02",
"fb": "21"
},
"wind": "旋转风微风",
"week": "星期二",
"date": "20150915"
},
{
"temperature": "18℃~21℃",
"weather": "中雨",
"weather_id": {
"fa": "08",
"fb": "08"
},
"wind": "东北风微风",
"week": "星期三",
"date": "20150916"
},
{
"temperature": "17℃~21℃",
"weather": "中雨",
"weather_id": {
"fa": "08",
"fb": "08"
},
"wind": "东北风微风",
"week": "星期四",
"date": "20150917"
},
{
"temperature": "19℃~24℃",
"weather": "小雨转阴",
"weather_id": {
"fa": "07",
"fb": "02"
},
"wind": "旋转风微风",
"week": "星期五",
"date": "20150918"
},
{
"temperature": "19℃~26℃",
"weather": "阴",
"weather_id": {
"fa": "02",
"fb": "02"
},
"wind": "旋转风微风",
"week": "星期六",
"date": "20150919"
},
{
"temperature": "19℃~27℃",
"weather": "阴",
"weather_id": {
"fa": "02",
"fb": "02"
},
"wind": "旋转风微风",
"week": "星期日",
"date": "20150920"
},
{
"temperature": "19℃~24℃",
"weather": "阴",
"weather_id": {
"fa": "02",
"fb": "02"
},
"wind": "旋转风微风",
"week": "星期一",
"date": "20150921"
}
]
},
"error_code": 0
}
通过
Gson gson = new Gson();
Book book = gson.fromJson(result, Book.class);
Log.i("info", book.getReason());
我能够得到 reason 的success的值,但是我想要得到result里面的today里面的week的值,请问我要怎么做?数组里面嵌套着数组,我迷茫了。
book.java如下:
public class Book {
private String reason;

public String getReason() {

return reason;

}

public void setReason(String reason) {

this.reason = reason;

}}

public static List getWeather(String json) {
List weatherModelList = new ArrayList();
//System.out.println(json + "json");

JSONTokener jsonParser = new JSONTokener(json);
WeatherModel weatherModel = null;
try {
    JSONObject object = (JSONObject) jsonParser.nextValue();
    System.out.println(object.getString("reason") + "---reason");
    if (object.getString("reason").equals("成功")) {
        JSONObject result = object.getJSONObject("result");
        JSONObject sk = result.getJSONObject("sk");
        weatherModel = new WeatherModel();
        weatherModel.setTemp(sk.getString("temp"));
        weatherModel.setWindDirection(sk.getString("wind_direction"));
        weatherModel.setWindStrength(sk.getString("wind_strength"));
        weatherModel.setHumidity(sk.getString("humidity"));
        weatherModel.setTime(sk.getString("time"));
        weatherModelList.add(weatherModel);
        weatherModel = null;
        JSONObject today = result.getJSONObject("today");
        weatherModel = new WeatherModel();
        weatherModel.setCity(today.getString("city"));
        weatherModel.setDatey(today.getString("date_y"));
        weatherModel.setWeek(today.getString("week"));
        weatherModel.setTemperature(today.getString("temperature"));
        weatherModel.setWeather(today.getString("weather"));
        weatherModel.setFa(today.getString("fa"));
        weatherModel.setFb(today.getString("fb"));
        weatherModel.setWind(today.getString("wind"));
        weatherModel.setDressing_index(today.getString("dressing_index"));
        weatherModel.setDressing_advice(today.getString("dressing_advice"));
        weatherModel.setUv_index(today.getString("uv_index"));
        weatherModel.setComfort_index(today.getString("comfort_index"));
        weatherModel.setWash_index(today.getString("wash_index"));
        weatherModel.setTravel_index(today.getString("travel_index"));
        weatherModel.setExercise_index(today.getString("exercise_index"));
        weatherModel.setDrying_index(today.getString("drying_index"));
        weatherModelList.add(weatherModel);
        weatherModel = null;
        JSONArray arr = result.getJSONArray("future");
        for (int i = 0; i < arr.length(); i++) {
            JSONObject cobject = (JSONObject) arr.get(i);
            weatherModel = new WeatherModel();
            weatherModel.setTemperature(cobject.getString("temperature"));
            weatherModel.setWeather(cobject.getString("weather"));
            weatherModel.setFa(cobject.getString("fa"));
            weatherModel.setFb(cobject.getString("fb"));
            weatherModel.setWind(cobject.getString("wind"));
            weatherModel.setWeek(cobject.getString("week"));
            weatherModel.setDate(cobject.getString("date"));
            weatherModelList.add(weatherModel);
} catch (JSONException e) {
    e.printStackTrace();
        我是这样写的
                                      2019-07-17 19:51:47
                            企业邮箱发送邮件时,若出现投递失败产生退信,内容提示包含如下: the mta server of * reply:550 failed to meet SPF requirements 或者 the mta server of 163.com — 163mx01.mxmail.netease.com(220.181.14.141) reply:550 MI:SPF mx14,QMCowECpA0qTiftVaeB3Cg—.872S2 1442548128 http://mail.163.com/help
                            303390
 
推荐文章
犯傻的海豚  ·  Next stop Davos! | Feroz Sheikh
4 月前
热情的煎鸡蛋  ·  像Excel一样使用python进行数据分析(2) - xitingxie - 博客园
1 年前
闷骚的山羊  ·  flask-apscheduler使用场景 - CSDN文库
1 年前
大力的长颈鹿  ·  Python爱好者社区历史文章列表 - 涵盖:Python网络爬虫、机器学习、深度学习、数据分析与挖掘等系列 - 知乎
2 年前
礼貌的海龟  ·  Java 比较两个JSONObject Java 比较两个Json jackson_mob6454cc6c6291的技术博客_51CTO博客
2 年前
今天看啥   ·   Py中国   ·   codingpro   ·   小百科   ·   link之家   ·   卧龙AI搜索
删除内容请联系邮箱 2879853325@qq.com
Code - 代码工具平台
© 2024 ~ 沪ICP备11025650号