在数据源中保存数据时遇到错误

时间:2014-12-15 08:13:48

标签: google-maps google-app-engine

我在使用Google地图引擎数据源保存数据时遇到问题。错误:缓冲区长度大于1:{"错误":{"错误":[{"域":"全球",& #34;原因":"无效","消息":"此值无效。" },"代码":400,"消息":"此值无效。" }}

其中"缓冲区长度大于1"是一个自定义消息。

特写:
     {"功能":[{"属性":{"姓名":" Vijay Tr"," Work_Email": " vijay.tomar@lovly.com"," Job_Title":"领导r","报告_位置":" Ind&# 34;," Total_Experience":9," MOBILE_PHONE":" 9313432451""部":" LINT&#34 ;, " gx_id":""," Reporting_To":" Ashish Gupta"},"输入":&#34 ;特征""几何" {"类型":"点""坐标":[77.02190399169922,28.455472946166992]}} ]}

功能是有效的Json。

 try {
        mapDataURL = new URL(url);
        if (mapDataURL != null) {
            urlConnection = mapDataURL.openConnection();
            urlConnection.setConnectTimeout(600000);
            urlConnection.setDoOutput(true);
            urlConnection.setRequestProperty("Content-Type","application/json");


            String gmeToken = saa.getOAuthTokenForMapsEngine();
            if (gmeToken != null && gmeToken.length() > 0) {
                urlConnection.setRequestProperty("Authorization", "Bearer " + gmeToken);
            }

            OutputStreamWriter wr = new OutputStreamWriter(urlConnection.getOutputStream());


            JSONArray latLngAry = new JSONArray();
            latLngAry.put(Float.parseFloat(lng));
            latLngAry.put(Float.parseFloat(lat));

        JSONObject geometry=new JSONObject();
            geometry.put("type","Point");
            geometry.put("coordinates",latLngAry);

        JSONObject jsonProperties=new JSONObject();
            jsonProperties.put("Name",name.trim());
            jsonProperties.put("Job_Title",jobTitle.trim());
            jsonProperties.put("Reporting_To",reportingTo.trim());
            jsonProperties.put("Department",department.trim());
            jsonProperties.put("Work_Email",email.trim());
            jsonProperties.put("Mobile_Phone",mobilePhone.trim());
            jsonProperties.put("Reporting_Location",reportingLocation.trim());
            jsonProperties.put("Total_Experience",Float.parseFloat(experience.trim()));
            jsonProperties.put("gx_id", "" + gx_id + "");

        JSONObject jsonFeature=new JSONObject();
            jsonFeature.put("properties", jsonProperties);  
            jsonFeature.put("type", "Feature");
            jsonFeature.put("geometry", geometry);

        String jsonStr = "{\"features\":[" + jsonFeature  + "]}";
        log.info("jsonStr : "+jsonStr); 

        wr.write(jsonStr);
            log.info(" writing String Success : "+wr.toString());
            wr.flush();
             log.info("Url : "+mapDataURL);
            // Get the response
        BufferedReader rd = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
            String line;
            while ((line = rd.readLine()) != null) {
                buffer.append(line);
            }
            wr.close();
            rd.close();

        }
    } catch (MalformedURLException e) {
        buffer = new StringBuffer("MalformedURLException : "+ e.getMessage() );


    } catch (IOException e) {
        buffer = new StringBuffer("IOException : " +e.getMessage());

    } catch (Exception e) {
        buffer = new StringBuffer("Generic Exception : "+e.getMessage());

    } finally {

    if (buffer.length() < 1) {
        return true;
    } else {
        log.info("buffer  length is greater than 1 : "+buffer.toString());
        return false;
    } 

    }

1 个答案:

答案 0 :(得分:0)

您打算在此处返回true吗?对于buffer.length() < 1,任何大于空缓冲区的值都将导致它返回false。因此,如果预计会调用buffer.append(line),您将始终返回false

我建议更改buffer.length() < 1条件。