How to retrieve the image_url from json to android.json code is here. I just want to get the image to a button.
{
"page_menu": {
"flag": "M"
},
"menu": [
{
"pid": "0",
"name": "Home",
"refid": "1",
"image_url": "aG9tZS5wbmc=",
"ord_field": "1"
},
{
"pid": "0",
"name": "About Us",
"refid": "2",
"image_url": "YWJvdXQucG5n",
"ord_field": "2"
},
{
"pid": "0",
"name": "Services",
"refid": "3",
"image_url": "c2VydmljZTIucG5n",
"ord_field": "3"
},
{
"pid": "0",
"name": "Products",
"refid": "4",
"image_url": "cHJvZHVjdHMucG5n",
"ord_field": "4"
}
]
}
here is my code for retrieve the json values, i did any mistakes ?? now also am not getting image
JSONArray jsonMainNode1 = jsonResponse.getJSONArray("menu");
int lengthJsonArr = jsonMainNode1.length();
for(int i=0; i <lengthJsonArr; i++)
{
JSONObject jsonChildNode = jsonMainNode1.getJSONObject(i);
String Pid = jsonChildNode.optString("pid".toString());
String Name = jsonChildNode.optString("name").toString();
String Refid=jsonChildNode.optString("refid".toString());
String image = jsonChildNode.getString("image_url");
byte[] decodedString = Base64.decode(image, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0,decodedString.length);
ImageView ima=new ImageView(getApplicationContext());
ima.setImageBitmap(decodedByte);
OutputData = Name+ima;
result is Home android.widget.imageview{4176f0c8VED..ID 0,0-0,0} like these..
my php code is here..
if(mysql_num_rows($result))
{
$json['page_menu']['flag'] = 'M';
while($row=mysql_fetch_assoc($result))
{
$json['menu'][$i]['pid']=ucwords($row['pid']);
$json['menu'][$i]['name']=$row['name'];
$json['menu'][$i]['refid']=$row['refid'];
$json['menu'][$i]['image_url']=base64_encode($row['image_url']);
$json['menu'][$i++]['ord_field']=$row['ord_field'];
}