Returning a blob with json Returning a blob with json android android

Returning a blob with json


Encode the binary data as base64 before you generate the JSON.

$obj->picture = base64_encode($binaryData);

You can then decode this in your Android application with any base 64 decoder. Since API level 8 there is a built in util class. Otherwise there are plenty of external libs you can use for targetting Android 2.1 or earlier.


you have to make BLOB to base64_encode

 while($spot = $results->fetch_assoc()){     $spots[] = $spot;                                                               }

Then prepare a foreach loop like this

foreach($spots as $key=>$value){    $newArrData[$key] =  $spots[$key];    $newArrData[$key]['picture'] = base64_encode($spots[$key]['picture']);    $newArrData[$key]['thumbnail'] = base64_encode($spots[$key]['thumbnail']);}header('Content-type: application/json');echo json_encode($newArrData);


It seems that json_encode works with UTF-8 encoded data only. You can use json_last_error() to detect json_encode error.