문제

Im using the following code to convert from a well-formed-String to a JSONObject in Java:

public void getStatus(){
    String status = "";
    try{
        String line;
        StringBuilder result = new StringBuilder("");
        HttpURLConnection conn;
        URL url;
        url = new URL("http://bromio.com.mx/explore/PointOfInterestService.svc/GetData");
        BufferedReader rd;
        conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        while ((line = rd.readLine()) != null) {
            result.append(line);
        }
        rd.close();
        Log.d("JSON: ", result.toString());
        JSONObject jsonObject = new JSONObject(result.toString());
    }catch (Exception e){
        e.printStackTrace();
    }
}

But it's throwing an exception, it seems that i cannot cast that specific string to JSONObject. The JSON can be acceses in this page: (It's too big to show!) http://bromio.com.mx/explore/PointOfInterestService.svc/GetData Any help solving this problem will help me a lot. thank you

도움이 되었습니까?

해결책

Let's take the first few characters of your json

 "{ \"poi\":[\u000d\u000a  
 ^  ^    ^   ^^^^^^
 |  |    |      |-----------> not sure about all this
 |  |    -------------------> not acceptable in json
 |  ------------------------> not acceptable in json
 ---------------------------> not acceptable in json

What you get back from that website is not valid root json. Fix your source if you have control over it. Or use the String utility methods to replace those characters.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top