Frage

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

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top