0

I am fetching data from a php server in its normal format..the columns are details and image.. I want the image in base64 format nd the details in utf8 format..all this data into one array that will be json encoded and will then be parsed at android side..How do i do this..so that i can Json parse in this manner..

 String result= convertStreamToString(is);
            JSONObject json=new JSONObject(result);
             jArray=json.getJSONArray("details");
            for(int i=0;i<jArray.length();i++)
            {
                JSONObject c=jArray.getJSONObject(i);
                String detail=c.getString("details");
                String image=c.getString("image");  
                Log.v("topics", topic);


            is.close();
            }   

The php code:

while($out=mysql_fetch_assoc($result))

{
echo $out;
print_r(base64_encode($out[image]));

echo base64_encode($out['image']);
echo utf8_encode($out['details']);

$tempImage = base64_encode($out['image']);
echo $tempImage;
$tempDetails = utf8_encode($out['details']);

$post[] = array("image"=>$tempImage);
$post []= array("details"=>$tempDetails);
}
echo json_encode(array("login"=>$post));
AndroidMech
  • 1,676
  • 3
  • 20
  • 31
  • can you post some part of your data? – SKT Nov 11 '13 at 06:06
  • Not your java code. Your returned php data – SKT Nov 11 '13 at 06:10
  • Image column is in blob..say an image of 8.7kib and the details columns is in datatype text on php server..so to retrieve the image i want it in base64 format..I m sorry i am not able to post the real data..coz its getting pasted a bit haphazard..so Sorry.. – AndroidMech Nov 11 '13 at 06:14
  • if($count!=0) { while($out=mysql_fetch_assoc($result)) //echo $out; //print_r(base64_encode($out[image])); //echo base64_encode($out['image']); //echo utf8_encode($out['details']); $tempImage = base64_encode($out['image']); echo $tempImage; //$tempDetails = utf8_encode($out['details']); //$post[] = array("image"=>$tempImage); //$post []= array("details"=>$tempDetails); – AndroidMech Nov 11 '13 at 06:15
  • and then i json encode $post[]...Sorry for the commented code and its format..i know its difficault..but plz help.. – AndroidMech Nov 11 '13 at 06:16
  • I believe, you are passing a file path for the image, you can try similar post http://stackoverflow.com/questions/9762057/how-to-download-file-image-from-url-to-your-android-app . Let me know if Im wrong on this. – rahul Nov 11 '13 at 06:19
  • edit your post with your code. Don't post code in comments. – URAndroid Nov 11 '13 at 06:20
  • I also tried getting all data in utf8 encode and then converting only the image string into base64..but while converting that base64 string into an image..it gives me skimagedrectory returns null or sumthing similar.. – AndroidMech Nov 11 '13 at 06:23
  • It has been done..URAndroid..So plz do have a look.. – AndroidMech Nov 11 '13 at 06:27
  • I am not passing a file Rahul..I am just recieving data from server..I am pretty sure that this a php issue..plz help.. – AndroidMech Nov 11 '13 at 06:38

1 Answers1

0

i think that you can use this link to learn about this

Issues-parsing data to the php and jsons

or visit this : http://androidexample.com/JSON_Parsing_-_Android_Example/index.php?view=article_discription&aid=71&aaid=95

Community
  • 1
  • 1
  • I have read those articles Ebrahim...but those appeared to be simple ones...what i am trying to achieve is diff..i want two different encodes format strings into one array..and then parsing it.. – AndroidMech Nov 11 '13 at 06:22