I want to show this JSON in a TextView in my Activity.
This is my JSON,
{
"AboutUs": [{
"p_content": "Dr. Vineet Malhotra currently working as a Consultant urologist where job description requires to run the urology units at these hospitals and perform various endourology, reconstructive and laparoscopic procedures. Dr. Vineet Malhotra associated with the department of urology for the last ten years and have been exposed to different practice methodologies.Dr. Vineet Malhotra have a special interest in recent advances in minimally invasive procedures in urology.\n"
}]
}
And this is my Activity where I want to display this JSON in TextView,
public class AboutUs extends AppCompatActivity {
private String TAG=MainActivity.class.getSimpleName();
private ProgressDialog pDialog;
TextView tv;
private static String url="http://softappsdemo.com/doctorplus/";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about_us);
Toolbar toolbar=(Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
new GetContacts().execute();
}
private class GetContacts extends AsyncTask<Void,Void,Void> {
protected void onPreExecute(){
super.onPreExecute();
pDialog=new ProgressDialog(AboutUs.this);
pDialog.setMessage("Please Wait ......");
pDialog.setCancelable(false);
pDialog.show();
}
protected Void doInBackground(Void... arg){
Handler sh=new Handler();
String jsonStr=sh.makeServiceCall(url);
Log.e(TAG,"Response from url : " +jsonStr);
if(jsonStr!=null){
try {
JSONObject jsonObj = new JSONObject(jsonStr);
JSONArray contacts = jsonObj.getJSONArray("AboutUs");
JSONObject c = contacts.getJSONObject(0);
String name = c.getString("p_content");
}catch (final JSONException e){
Log.e(TAG,"Json parsing error: " +e.getMessage());
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),"JSON parsing error: " +e.getMessage(),Toast.LENGTH_LONG).show();
}
});
}
}else {
Log.e(TAG,"Could not get JSON from server.");
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),"could not get JSOM from server check logcat if possible " ,Toast.LENGTH_LONG).show();
}
});
}
return null;
}
protected void onPostExecute(Void result){
super.onPostExecute(result);
if (pDialog.isShowing())
pDialog.dismiss();
}
}
}
Where I should have to put the code for TextView?
Please help me guys. Thanks in advance.
TextViewtext?String namevariable as global and in onPostExecute method set the content inTextView.