我有一个由这个 php 生成的 json 数组:
$filtros=mysql_query("SELECT id_transporte FROM user_trans WHERE id_usuario = '".$id_usuario ."'");
for($i=0; $i<=mysql_num_rows($filtros); $i++){
$rs[]= mysql_fetch_array($filtros,MYSQL_ASSOC);
}
foreach($rs as $valor){
if (is_array($valor)) {
foreach($valor as $valor1){
$reportes[]= mysql_query("
SELECT * FROM transportes
WHERE id_transporte='".$valor1."'
ORDER BY fecha_reporte DESC ");
}
}
}
foreach($reportes as $valor){
if($valor != false){
for($i=0; $i<=mysql_num_rows($valor); $i++){
$row[]= mysql_fetch_array($valor,MYSQL_ASSOC);
}
}
}
print_r (json_encode($row));
返回:
[{"id_report":"73","id_transport":"624","txt_report":"Report0"},
{"id_report":"46","id_transport":"624","txt_report":"Report1"},false,
{"id_report":"74","id_transport":"9999","txt_report":"Report2"},
{"id_report":"52","id_transport":"9999","txt_report":"Report3"},false]
好吧,我尝试读取它,但 java 只读取到“false”...该数组是 2 个连接并打印的数组,所以我试试这个:
$row1=str_replace ( "false" , '{"salto":1}' , $row );
$row1[]=false;
print_r (json_encode($row1));
返回相同但“”而不是“假”和“假”最后但java继续读取直到现在“”我用它来读取json
if (jdata!=null && jdata.length() > 0){
JSONObject json_data = null;
try{
System.out.println( jdata.length() );//java there print all the array length ignoring the "false" o ""
for (int i=0; i < jdata.length(); i++){
reportsId[i]=jdata.getJSONObject(i).getString("id_report");
transportId[i]=jdata.getJSONObject(i).getString("id_transport");
txt_report[i]=jdata.getJSONObject(i).getString("txt_report");
System.out.println( " i= "+ i);
}
}
}catch(Exception e3){}
所以我的问题是如何阅读这个,或者在 php 上更改一些行