Server sends json data correctly. Client parses it wrong

Posted by alois.wirkes on Stack Overflow See other posts from Stack Overflow or by alois.wirkes
Published on 2012-10-11T21:25:25Z Indexed on 2012/10/11 21:37 UTC
Read the original article Hit count: 163

Filed under:
|

I have a PHP code that generates a JSON string to send to my Android app. This part works. The problem is when my app captures that string and try to convert it into a JSONArray object. The main idea is to store that data inside a SQLite database.

Here's the code that captures the JSON string:

public void getPostResponse(){
    try{
        br = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
        sb = new StringBuilder();
        line = null;
        while((line = br.readLine()) != null){
            sb.append(line+"\n");
        }
        is.close();
        result = sb.toString();
        Log.e("getPostResponse","result= "+sb.toString());
    }catch(Exception e){
        Log.e("log_tag","Error converting result "+e.toString());
    }
}

And this is the result in the LogCat:

10-11 16:27:01.171: E/getPostResponse(9155): result= [{ "establecimientos":[]},{ "rutas":[]},{ "formularios":[]},{ "clientes":[]},{ "mediciones":[]}]

This is why I think there's an error, the result variable should contain the whole JSON string and it doesn't. Any ideas?

Variables br, sb, line and result are declared globally. JSON sent from server is already a JSONArray (starts with '[' and ends with ']'), is this what's causing the problem?

© Stack Overflow or respective owner

Related posts about android

Related posts about JSON