Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to convert JSON response to String and show in screen?
    primarykey
    data
    text
    <p>I have written android class which will call RESTful web service. If request is successful, response will be JSON object. I write android class like this:</p> <p>public class android extends Activity {</p> <pre><code> public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TextView txt = (TextView) findViewById(R.id.textView1); txt.setText(getInputStreamFromUrl("http://localhost:8080/kyaw")); } public static String getInputStreamFromUrl(String url) { InputStream content = null; try { HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = httpclient.execute(new HttpGet(url)); content = response.getEntity().getContent(); } catch (Exception e) { Log.e("[GET REQUEST]", "Network exception"); } String result=convert(content); return result; } private static String convert(InputStream in) { BufferedReader reader=new BufferedReader(new InputStreamReader(in)); StringBuilder sb=new StringBuilder(); String line=null; try{ while((line=reader.readLine())!=null){ sb.append(line+"\n"); } }catch(Exception e) { e.printStackTrace(); }finally{ try{ in.close(); }catch(IOException e){ e.printStackTrace(); } } return sb.toString(); } </code></pre> <p>}</p> <p>I have a problem after i run.I will get exception coz i return as a string.But response is JSON .How should I convert JSON to String or other way and then how to show result in android screen?</p> <p>thanks<img src="https://i.stack.imgur.com/FnHzf.jpg" alt="enter image description here"></p>
    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