I am get the json data from php. and pass to android
Here is my php code:
<?php
mysql_connect("localhost","root","MobixMySQL");
mysql_select_db("cozydine");
$q=mysql_query("SELECT itemimage from fooditem");
while($obj=mysql_fetch_object($q)){
$arr[]=$obj;
}
echo '{"names":'.json_encode($arr).'}';
mysql_close();
?>
And here is how I read the image:
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 + "
");
}
is.close();
result = sb.toString();
jArray = new JSONObject(result);
JSONArray json = jArray.getJSONArray("names");
for (int i = 0; i < json.length(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
JSONObject e = json.getJSONObject(i);
Qrimage=e.getString("itemimage");
System.out.println(Qrimage);
byte[] qrimage = Base64.decode(Qrimage.getBytes());
System.out.println(qrimage);
bmp = BitmapFactory.decodeByteArray(qrimage, 0,qrimage.length);
ImageView imageview=(ImageView) findViewById(R.id.imageView1);
imageview.setImageBitmap(bmp);
Here is how I parse the response from the php code:
codeInputStream is = null;
String result = "";
JSONObject jArray = null;
try {
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(serverurl+"showall.php");
HttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch (Exception e) { }
In that way i can view only last image in my android mobile .. I want display all images from database into android mobile please help me how to get all images using json data