Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to convert gson data to a string using json
    primarykey
    data
    text
    <p>im trying to convert a json object to a string by using gson here is some of my code</p> <pre><code>public void returnJson(){ TextView one = (TextView) findViewById(R.id.textView1); try{ HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost("http://10.0.2.2/textures_story_list.php"); HttpResponse response = httpClient.execute(httpPost); HttpEntity entity = response.getEntity(); is = entity.getContent(); }catch(Exception e) { one.setText("error3"); } try{ BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); result = sb.toString(); }catch(Exception e) { one.setText("error2"); } try{ JSONArray jArray = new JSONArray(result); for(int i = 0;i&lt;jArray.length();i++){ JSONObject json_data = jArray.getJSONObject(0); //Log.i("log_tag","story_name: "+json_data.getString("story_name") ); result += "\n" + jArray.getJSONObject(i); } one.setText(result); } catch(JSONException e) { one.setText("error1"); } return; //end of returnJson() } </code></pre> <p>this is what is outputs into the text view</p> <pre><code>[{"story_name":"Story One"},{"story_name":"Story Two"},{"story_name":"Story Three"},{"story_name":"Story Four"},{"story_name":"Story Five"},{"story_name":"Story Six"}] {"story_name":"Story One"} {"story_name":"Story Two"} {"story_name":"Story Three"} {"story_name":"Story Four"} {"story_name":"Story Five"} {"story_name":"Story Six"} </code></pre> <p>exactly like that, i need to know why it outputs it twice and which codes cause each output, then i also need to know how to change this with gson so it outputs</p> <pre><code>Story One Story Two Story Three Story Four Story Five Story Six </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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