org.json.JSONException android

时间:2015-05-23 13:05:48

标签: android android-volley

我得到jsonarray我已经通过下面的排球做了jsonarray请求是检查json的网址。  问题是我没有得到回应。

String url="http://reesguru.com/DesktopModules/ReEsServer/API/PropertyWebService/GetDataForSearchBySaleProperty?location=&propertyFor=1&propertyType=0&bathroom=0&bedroom=0&minprice=0&maxprice=0&mincoverarea=0&maxcoverarea=0&minplotarea=0&maxplotarea=0&Possession=0&TransactionType=0&orderby=UsdMonthlyRent&orderto=Desc";

        JsonArrayRequest request=new JsonArrayRequest(url,new Response.Listener<JSONArray>() {

            @Override
            public void onResponse(JSONArray response) {
                // TODO Auto-generated method stub
                try {


                Log.e("response",String.valueOf(response));
                for(int i=0;i<response.length();i++)
                {
                     JSONObject obj = response.getJSONObject(i);

                        String title = obj.getString("Title");
                        Log.e("title", String.valueOf(title));
                }

                } catch (JSONException e) {
                    Log.e("e", e.getMessage());
                }
            }

        },new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError e) {
                // TODO Auto-generated method stub
                Log.e("error",e.getMessage());
            }
        });
queue.add(request);

} 提前你好。

这是我的例外情况。我在异常

中得到了一半的回应
org.json.JSONException: Value[{"ProjectID":12,"ProjectseId":"Pr5735385","AgentId":33,"UserId":10,"Title":"Sunshine","Description":"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi …","Url":"www.vapiview.com","ProjectFor":1,"ProjectType":4,"ViewType":"0","FloorNumber":null,"TotalFloor":null,"ProjectSubType":41,"KeyLandmark":"MadhuBan Dem","LandArea":null,"LandAreaUnit":null,"Possession":null,"TransactionType":null,"NoofBedrooms":null,"NoofBathrooms":null,"NoofKitchen":null,"NoofBalcony":null,"FaceView":null,"ProjectAge":1,"Location":"Vapi","City":"Vapi","Postcode":"WC1B 4BB","ProjectOwnership":null,"DistanceDetails":"RailwayStation:12.00","SalePrice":0.00,"Furnished":null,"HomeFeaturesList":"","SocietyFeaturesList":"","OtherFeaturesList":"","Latitude":20.000000000000000,"Longitude":20.000000000000000,"ZoomValue":3,"IsDeleted":false,"upsize_ts":"AAAAAAAA8ho=","currencyunit":"","UsdSalePrice":0.00,"BuiltArea":null,"BuiltAreaUnit":null,"Project_QRCode":null,"GeoLocation_QRCode":null,"KeyName":"Commercial","ProjectImage":"/DesktopModules/ReEsWeb/Images/Property-Images/crop_20140603154802.jpg"},{"ProjectID":13,"ProjectseId":"Pr5735385","AgentId":33,"UserId":10,"Title":"Sunshine","Description":"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi …","Url":"www.vapiview.com","ProjectFor":1,"ProjectType":3,"ViewType":"0","FloorNumber":null,"TotalFloor":null,"ProjectSubType":37,"KeyLandmark":"MadhuBan Dem","LandArea":null,"LandAreaUnit":null,"Possession":null,"TransactionType":null,"NoofBedrooms":null,"NoofBathrooms":null,"NoofKitchen":null,"NoofBalcony":null,"FaceView":null,"ProjectAge":1,"Location":"Vapi","City":"Vapi","Postcode":"WC1B 4BB","ProjectOwnership":null,"DistanceDetails":null,"SalePrice":0.00,"Furnished":null,"HomeFeaturesList":null,"SocietyFeaturesList":null,"OtherFeaturesList":null,"Latitude":21.190109900000000,"Longitude":72.813936900000040,"ZoomValue":8,"IsDeleted":false,"upsize_ts":"AAAAAAAA8hs=","currencyunit":"","UsdSalePrice":0.00,"BuiltArea":null,"BuiltAreaUnit":null,"Project_QRCode":"/DesktopModules/ReEsWeb/Images/QRCodeImages/ProjectQRCode/13ProjectQRCode.jpg","GeoLocation_QRCode":"/DesktopModules/ReEsWeb/Images/QRCode_GeoLocationImages/ProjectGeoLocationImages/13GeoLocationQRCode.jpg","KeyName":"Residential","ProjectImage":null},{"ProjectID":14,"ProjectseId":"Pr5735385","AgentId":33,"UserId":10,"Title":"Sunshine","Description":"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi …","Url":"www.vapiview.com","ProjectFor":1,"ProjectType":4,"ViewType":"0","FloorNumber":0,"TotalFloor":0,"ProjectSubType":41,"KeyLandmark":"MadhuBan Dem","LandArea":0.0,"LandAreaUnit":"0","Possession":"1","TransactionType":0,"NoofBedrooms":1,"NoofBathrooms":1,"NoofKitchen":1,"NoofBalcony":1,"FaceView":"0","ProjectAge":1,"Location":"Vapi","City":"Vapi","Postcode":"WC1B 4BB","ProjectOwnership":null,"DistanceDetails":"","SalePrice":0.00,"Furnished":"Fully","HomeFeaturesList":null,"SocietyFeaturesList":null,"OtherFeaturesList":null,"Latitude":0.000000000000000,"Longitude":0.000000000000000,"ZoomValue":0,"IsDeleted":false,"upsize_ts":"AAAAAAAA8hw=","currencyunit":"","UsdSalePrice":0.00,"BuiltArea":0.0,"BuiltAreaUnit":"","Project_QRCode":null,"GeoLocation_QRCode":null,"KeyName":"Commercial","ProjectImage":null},{"ProjectID":15,"ProjectseId":"Pr5735385","AgentId":33,"UserId":10,"Title":"TestProject","Description":"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi …","Url":"www.google.com","ProjectFor":1,"ProjectType":3,"ViewType"
at org.json.JSON.typeMismatch(JSON.java:111)
at org.json.JSONObject.<init>(JSONObject.java:158)
at org.json.JSONObject.<init>(JSONObject.java:171)

3 个答案:

答案 0 :(得分:1)

好!如果我尝试使用代码段中提供的Rest URL,我会收到ParseError这样的内容:

enter image description here

所以查明问题我尝试了几件事,并最终接受了您的回复,并创建了一个公共要点here,其中包含您从Web服务URL获得的相同响应,然后我没有收到任何错误。

我可以指出的差异是“描述”标签中的一些特殊字符。

在我创建的主旨中,它显示为nisi … 如果您在Chrome中打开回复,则会显示为nisi … 在eclipse中调试时,它显示为nisi …

您的WS响应肯定存在一些编码问题。如果你能以某种方式对这些角色进行一些调整,你就可以使它发挥作用。

<强>更新 我现在在AdvancedRestClient尝试了您的请求(您可以将此应用添加到您的Chrome浏览器中),并发现您的回复位于"",其中所有回复都嵌入在 {之间your_json_object} 因此无法通过Volley API进行解析。

enter image description here

如果您正在徘徊,有效的JSON响应如何,请尝试使用http://api.androidhive.info/json/movies.json

理想情况下应如下所示:

enter image description here

所以回到你的WS :)让我知道它是怎么回事!

答案 1 :(得分:0)

没有&#34; PropertyID&#34;作为对此网址的回应:

String url="http://reesguru.com/DesktopModules/ReesServer/API/PropertyWebService/GetDataForSearchByProject?location=&ProjectFor=1&projectType=0&bathroom=0&bedroom=0&minprice=0&maxprice=0&mincoverarea=0&maxcoverarea=0&minplotarea=0&maxplotarea=0&Possession=0&TransactionType=0&orderby=UsdSalePrice&orderto=Desc&currencyto=";

如果你需要&#34; ProjectID&#34;相反,作为&#39; apk&#39;回答,注意它不是String,它是int。

String name = String.valueOf(obj.getInt("ProjectID"));

答案 2 :(得分:-1)

isuue是这一行String name = obj.getString(“PropertyID”);它应该是

String name = obj.getInt("ProjectID");