I am using httpurlconnection and I can't find understandeble way to parse my json. attribute output return this json {"value":"SUCCESS"} but how to parse the json?
code
protected Void doInBackground(String... params) {
String ue=params[1];
try {
//final TextView outputView = (TextView) findViewById(R.id.showOutput);
URL url = new URL("my url return json ");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
String urlParameters = "e="+ue;
connection.setRequestMethod("POST");
connection.setRequestProperty("USER-AGENT", "Mozilla/5.0");
connection.setRequestProperty("ACCEPT-LANGUAGE", "en-US,en;0.5");
connection.setDoOutput(true);
DataOutputStream dStream = new DataOutputStream(connection.getOutputStream());
dStream.writeBytes(urlParameters);
dStream.flush();
dStream.close();
int responseCode = connection.getResponseCode();
System.out.println("\nSending 'POST' request to URL : " + url);
System.out.println("Post parameters : " + urlParameters);
System.out.println("Response Code : " + responseCode);
final StringBuilder output = new StringBuilder("Request URL " + url);
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line = "";
StringBuilder responseOutput = new StringBuilder();
System.out.println("output===============" + br);
while((line = br.readLine()) != null ) {
responseOutput.append(line);
}
br.close();
output.append(System.getProperty("line.separator") + "Response " + System.getProperty("line.separator") + System.getProperty("line.separator") + responseOutput.toString());
register.this.runOnUiThread(new Runnable() {
@Override
public void run() {
//output;
try {
JSONObject json = new JSONObject(output.toString());
message = json.optString("value");
} catch (JSONException e) {
e.printStackTrace();
}
Toast.makeText(register.this,"output: "+output, Toast.LENGTH_SHORT).show();
progress.dismiss();
}
});
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
protected void onPostExecute() {
progress.dismiss();
}
if there is any dependences that I should to add to gradel.Please, let me know! thank you in advance