Note that there are some explanatory texts on larger screens.

plurals
  1. POconvert JSON to string from sql DB by php
    primarykey
    data
    text
    <p>i have an app that should display a string in a textview after the buttons clicked, instead it displays the JSON format of the code not the uncoded JSON. here is my android code</p> <pre><code> package game.com; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.TextView; public class JSONtestActivity extends Activity { String result = ""; InputStream is = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button btn = (Button) findViewById(R.id.button1); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { TextView one = (TextView) findViewById(R.id.textView1); returnJson(); //end of onClick } //end of onClickListener }); //end of oncreate() } 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(i); 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() } //end of class body } </code></pre> <p>and my php</p> <pre><code>&lt;?php mysql_connect("127.0.0.1","root"); mysql_select_db("textures_story_list"); $sql=mysql_query("SELECT story_name FROM story_list WHERE story_name LIKE 'sto%'"); while($row=mysql_fetch_assoc($sql)) $output[]=$row; print(json_encode($output)); mysql_close(); ?&gt; </code></pre> <p>can someone help with y it doesnt display the names instead of the json format this is what it displays in the textview instead of story one, story two and so on</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"}]/n{"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>
    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