Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, my problem is that when i try to parse from my wcf service into android it gives me an error. the return for my service is with JSON. this is my android code:

DefaultHttpClient client = new DefaultHttpClient();
// http get request
HttpGet request = new HttpGet("http://192.168.1.125:8181/Managers/Authentification.svc/authen/?loga="+t1.getText().toString()+"&pass="+t2.getText().toString());

// set the hedear to get the data in JSON formate
request.setHeader("Accept", "application/json");
request.setHeader("Content-type", "application/json");

//get the response
HttpResponse response = client.execute(request);
System.out.println("Connectee--->" +response.getAllHeaders());

HttpEntity entity = response.getEntity();

//if entity contect lenght 0, means no data exist in the system with these code
if(entity.getContentLength() != 0) {
// stream reader object
Reader employeeReader = new InputStreamReader(response.getEntity().getContent());
//create a buffer to fill it from reader
char[] buffer = new char[(int) response.getEntity().getContentLength()];
//fill the buffer by the help of reader
employeeReader.read(buffer);
//close the reader streams
employeeReader.close();

//for the employee json object
JSONObject tt = new JSONObject(new String(buffer));

System.out.println("..................OK.........................");

System.out.println("Reference: " + tt.getString("Reference"));
}
else {
System.out.println("...................Not OK........................");
}

}
catch (JSONException e) {
System.out.println("...................ERRORJSON........................");
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println("...................ERROR........................");
e.printStackTrace();
}

}
});
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900