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那么这个就会无限循环下去,就会在栈中不断调用方法,直至栈溢出。

自己遇到过的出现java.lang.StackOverflowError的原因的更多相关文章

  1. 页面上使用 Thymeleaf 的内联js不当造成了 java.lang.StackOverflowError: null 问题

    由于在页面上内联js使用不当,从而在从 Controller 跳转到页面时发生了以下错误: java.lang.StackOverflowError: null at org.thymeleaf.ut ...

  2. 错误笔记:Caused by: java.lang.StackOverflowError

    今天在将一个map转化成json出现堆栈异常,排查原因如下:出现循环递归( rootMap.put("rootMap", rootMap);),栈内存肯定耗光 代码: /** * ...

  3. Jackson转换对象为json的时候报java.lang.stackoverflowerror

    无论在将一个对象转为json字符串的时候采用何种算法,如果你的对象的属性的类型不是基本类型或对应的引用类型,转换应该都不会就此结束,那么有一种方式可以导致这种转换陷入无限循环:将某个对象的属性设为对象 ...

  4. struts2 java.lang.StackOverflowError org.apache.struts2.json.JSONWriter

    1. 问题描述: 页面通过异步访问action,    action的方法通过map封装数据,struts的result的type设置为json,后台报错 六月 25, 2016 6:54:33 下午 ...

  5. java.lang.StackOverflowError: stack size 8MB

    java.lang.StackOverflowError: stack size 8MB at android.text.TextUtils.getChars(TextUtils.java:86) a ...

  6. android布局太深导致的 java.lang.StackOverflowError

    E/AndroidRuntime( 1900): java.lang.StackOverflowError E/AndroidRuntime( 1900):     at android.graphi ...

  7. 【转】java.lang.StackOverflowError

    http://blog.csdn.net/g19920917/article/details/8765638 出现一个java.lang.StackOverflowError异常.弄了半天,又是问高手 ...

  8. 异常Exception in thread "AWT-EventQueue-XX" java.lang.StackOverflowError

    今天太背了,bug不断,检查到最后都会发现自己脑残了,粗心写错,更悲剧的是写错的时候还不提示错. 刚才有遇到一个问题,抛了这个异常Exception in thread "AWT-Event ...

  9. org.springframework.web.util.NestedServletException : Handler processing failed; nested exception is java.lang.StackOverflowError

    1 ,错误原因,循环冗余检查      result.setNearUsers(userList);            Page page = new Page();            pag ...

随机推荐

  1. MyBatis - 2.全局文件配置

    1.properties 属性 <!--properties 引入外部配置文件 properties 的内容 resource: 引入类路径资源 url: 引入网络资源 --> <p ...

  2. 一脸懵逼学习Struts数据校验以及数据回显,模型驱动,防止表单重复提交的应用。

    1:Struts2表单数据校验: (1)前台校验,也称之为客户端校验,主要是通过Javascript编程的方式进行数据的验证. (2)后台校验,也称之为服务器校验,这里指的是使用Struts2通过xm ...

  3. php函数xml转化数组

    /** * xml转数组 * @param $xml * @return array */ function xml_to_array( $xml ) { $reg = "/<(\\w ...

  4. 一起学Hive——详解四种导入数据的方式

    在使用Hive的过程中,导入数据是必不可少的步骤,不同的数据导入方式效率也不一样,本文总结Hive四种不同的数据导入方式: 从本地文件系统导入数据 从HDFS中导入数据 从其他的Hive表中导入数据 ...

  5. Flink--输入数据集Data Sources

    flink在批处理中常见的source flink在批处理中常见的source主要有两大类. 1.基于本地集合的source(Collection-based-source) 2.基于文件的sourc ...

  6. libssl.so.10: cannot open shared object file: No such file or directory

    今天在使用yum安装东西的时候报错 yum list There was a problem importing one of the Python modulesrequired to run yu ...

  7. python各个包的用途

    python中的多个包的用途 1.Numpy Numpy提供了两种基本的对象:ndarray和ufunc.ndarray是存储单一数据类型的多维数组,而ufunc是能够对数组进行处理的函数. N维数组 ...

  8. MySQL函数大全 及用法示例

      字符串函数 ASCII(str)    返回字符串str的第一个字符的ASCII值(str是空串时返回0)  mysql> select ASCII('2');   -> 50  my ...

  9. JavaScript 组数去重demo

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  10. day4 class work answer

    count=0 s = input("请输入内容:") # asd234fsdafa5456fsdaf1 while s: s=s.lstrip("abcdefghijk ...