问题是当其中一个值是Base 64编码的Image时,有时它会回显 JSON_ERROR_SYNTAX 。 我相信它可能与无效字符有关,但我是php的新手,无法在网络上找到任何信息。 此错误仅发生在某些图像上,其他图像正确回显,因此它与json格式无关,但在某些base 64加密时。
Json看起来像:
{" name":" testName"," description":" testDescription"," image":& #34; base64encodedImageHere"}
这是php收件人文件:
<?php
header('Content-Type: application/json');
if (isset($_POST['ImageData'])){
$data = $_POST['ImageData'];
$imageData = json_decode($data,true);
switch(json_last_error()) {
case JSON_ERROR_NONE:
echo ' - Sin errores';
break;
case JSON_ERROR_DEPTH:
echo ' - Excedido tamaño máximo de la pila';
break;
case JSON_ERROR_STATE_MISMATCH:
echo ' - Desbordamiento de buffer o los modos no coinciden';
break;
case JSON_ERROR_CTRL_CHAR:
echo ' - Encontrado carácter de control no esperado';
break;
case JSON_ERROR_SYNTAX:
echo ' - Error de sintaxis, JSON mal formado';
break;
case JSON_ERROR_UTF8:
echo ' - Caracteres UTF-8 malformados, posiblemente están mal codificados';
break;
default:
echo ' - Error desconocido';
break;
}
foreach ($imageData as $k=>$v){
echo $v; // etc.
}
}else{
echo "out of reach"
?>
&LT;&LT;&LT;&LT;编辑:&gt;&gt;&gt;&gt;对于那些要求真正的json的人来说,虽然客户输出仍然没有显示整体价值,但它比我可以粘贴的更大:
"name":"testName",
"description":"testDescription",
"image":"\/9j\/4AAQSkZJRgABAQAAAQABAAD\/2wBDAAIBAQEBAQIBAQECAgICAgQDAgICAgUEBAMEBgUGBgYF\nBgYGBwkIBgcJBwYGCAsICQoKCgoKBggLDAsKDAkKCgr\/2wBDAQICAgICAgUDAwUKBwYHCgoKCgoK\nCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgr\/wAARCAmQDMADASIA\nAhEBAxEB\/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL\/8QAtRAAAgEDAwIEAwUFBAQA\nAAF9AQIDAAQRBRIhMUEGE1Fh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