HERE is php file result
Array[{"username":"abc","userpassword":"abc","id":"123456789"}]
Here is Code of getting response through HTTPConnection ..
protected String doInBackground(String... params) {
HttpURLConnection conn = null;
try {
// create connection
URL wsURL=new URL(params[0]);
conn=(HttpURLConnection) wsURL.openConnection();
conn.setConnectTimeout(15000);;
conn.setReadTimeout(10000);
// get data
InputStream in = new BufferedInputStream(conn.getInputStream());
// converting InputStream into String
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(in,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "
");
}
in.close();
String jsonResult=sb.toString();
return jsonResult;
}
catch(Exception e){
Log.e("log_tag", "Error converting result " + e.toString());
}
And The Code Through Which i am parsing string result into jsonArray and JsonObject
protected void onPostExecute(String result) {
try {
JSONArray jArray = new JSONArray(result);
JSONObject json = jArray.getJSONObject(0);
String username = json.getString("username");
} catch (Exception e) {
error2 = e.getMessage().toString();
// TODO: handle exception
Log.e("log_tag", "Error Parsing Data "+e.toString());
}
dialog.dismiss();
}
There is an error that "Value of type java.lang.String cannot be converted to JSONArray"