Note that there are some explanatory texts on larger screens.

plurals
  1. POFetching PNR status from PNR no. using json
    primarykey
    data
    text
    <blockquote> <p><strong>I am android beginner and trying to fetch pnr status using json here is my code which is not working please help me .</strong> Also tell me which parsing method is goo xml parse or json parse. When you asking questions, using some more words to describe your problem will always help. If there are really nothing more to say, just copy some random paragraph from internet, but make sure you mark them as dummy text so that people won't pay attention on them.</p> </blockquote> <pre><code> public class JSON extends Activity { String completeData=""; TextView tv; EditText et; Button bt; HttpClient client; JSONObject jsonobj; final static String URI="http://pnrapi.alagu.net/api/v1.0/pnr/"; String pnr_no=null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_json); tv=(TextView) findViewById(R.id.textView1); et=(EditText) findViewById(R.id.editText1); bt=(Button) findViewById(R.id.button1); client=new DefaultHttpClient(); } public void showpnr(View v){ pnr_no=et.getText().toString(); if(pnr_no.equals("")){ Toast.makeText(this, "Enter the Valid Pnr", Toast.LENGTH_LONG).show(); return; } GetPNR pnr=new GetPNR(); pnr.execute("train-name"); completeData=""; } public JSONArray pnr(String username){ JSONArray jarray=null; try { StringBuilder builder=new StringBuilder(URI); builder.append(username); HttpGet get=new HttpGet(builder.toString()); HttpResponse response=client.execute(get); int status =response.getStatusLine().getStatusCode(); if(status==200){ HttpEntity entity=response.getEntity(); String data=EntityUtils.toString(entity); jarray=new JSONArray(data); } else{ Toast.makeText(this, "Error", Toast.LENGTH_LONG).show(); } }catch(ClientProtocolException e){ e.printStackTrace(); } catch(IOException e){ e.printStackTrace(); } catch(JSONException e){ e.printStackTrace(); } catch(Exception e){ e.printStackTrace(); } return jarray; } JSONObject js_pnr=new JSONObject(); public class GetPNR extends AsyncTask&lt;String, Integer, ArrayList&lt;String&gt;&gt; { @Override protected void onPreExecute() { // TODO Auto-generated method stub tv.setText("Loading Pnr status"); super.onPreExecute(); } @Override protected ArrayList&lt;String&gt; doInBackground(String... params) { // TODO Auto-generated method stub ArrayList&lt;String&gt; al_texts=new ArrayList&lt;String&gt;(); try{ JSONArray data =pnr(pnr_no); if(data==null){ return null; } int count=data.length(); JSONObject jobj=new JSONObject(); for(int i=0;i&lt;count;i++){ jobj=data.getJSONObject(i); al_texts.add(jobj.getString("train-name").toString()); } return al_texts; }catch(JSONException e){ e.printStackTrace(); } return null; } @Override protected void onPostExecute(ArrayList&lt;String&gt; al_pnrText) { if(al_pnrText==null){ tv.setText("Pnr not found"); return; } for(String string:al_pnrText){ completeData+=string+System.getProperty("line.seperator") +System.getProperty("line.seperator"); } tv.setText("pnr status:"+System.getProperty("line.seperator")+completeData); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload