博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
自己遇到过的出现java.lang.StackOverflowError的原因
阅读量:7238 次
发布时间:2019-06-29

本文共 1235 字,大约阅读时间需要 4 分钟。

    public static JSONArray geth24Weather(String result) {//获取当天24小时以及第二天的天气结果对象

        JSONObject fromObject = null;
        JSONArray h24weatherArray =null;
        try {
            int indexOf = result.indexOf("{");
            int lastIndexOf = result.lastIndexOf("}");
            result=result.substring(indexOf, lastIndexOf+1);
            String replaceAll = result.replaceAll(" ", "");
            if(replaceAll.trim().startsWith("{")){
            fromObject = JSONObject.fromObject(result);
            }
            //System.out.println("fromObject"+fromObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if(fromObject!=null&&fromObject.get("code").equals("0")){
             JSONArray jsonArray = fromObject.getJSONArray("data");//获取天气数据对象
             JSONArray  forecastArray= ((JSONObject)jsonArray.get(0)).getJSONArray("forecast");//获取预报天气对象
             JSONObject todayObj= (JSONObject)forecastArray.get(0);//获取到当天对象
             if(todayObj.containsKey("h24weather")&&todayObj.get("h24weather")!=null){
                 System.out.println("打印todayObj="+todayObj);
                 h24weatherArray=todayObj.optJSONArray("h24weather");
                if(h24weatherArray==null){
                     geth24Weather(result);
                 }
                 System.out.println("打印h24weatherArray="+h24weatherArray);
             }else{
                
                 System.out.println("空");
             }
            
        }
        return h24weatherArray;
    }

这个就是递归没有结束条件,一旦遇到result是null那么这个就会无限循环下去,就会在栈中不断调用方法,直至栈溢出。

转载于:https://www.cnblogs.com/wth21-1314/p/9288269.html

你可能感兴趣的文章
MySQL 5.6学习笔记(数据表基本操作)
查看>>
复制控制---复制构造函数
查看>>
bash把所有屏幕输出重定向到文件并保持屏幕输出的方法
查看>>
HBase 压缩算法设置及修改
查看>>
深入了解jquery中的键盘事件
查看>>
windows常用命令行整理
查看>>
DotNet中人民币符号的输出
查看>>
Spark源码分析 – SchedulerBackend
查看>>
正则表达式
查看>>
C语言中结构体 自引用 和 相互引用
查看>>
awk substr()函数
查看>>
git diff的用法
查看>>
[SQL基础]入门
查看>>
s3cmd 安装使用指南
查看>>
hdu 1253:胜利大逃亡(基础广搜BFS)
查看>>
sdut 2153:Clockwise(第一届山东省省赛原题,计算几何+DP)
查看>>
代码修改mysql字符
查看>>
Android 新加几个开源项目
查看>>
Mysql 不同版本 说明
查看>>
ADT下载地址整理(转)
查看>>