我有一个写JSON的PHP脚本。它在所有情况下都非常有效,但仅在一种情况下有效:如果我从较新的Android(相对于较旧的Android,iOS或台式机)不安全地调用它,则会在输出中不规则地插入两位十六进制数字:>
**40** { "query":"SELECT * FROM mySQL_table ORDER BY `Time` ASC ",
**16** "success":5,
"data":[ **a8** { "Player":"Jay",
"Crime1":"",
"Crime2":"",
"Crime3":"",
"Partners1":"",
"Partners2":"",
"Partners3":"",
"Suspects":"",
"Time":"2018-10-30 13:17:04" 4
},
**55** { "Player":"Moto",
"Crime1":"",
"Crime2":"",
"Crime3":"",
"Partners1":"",
**35** "Partners2":"",
"Partners3":"",
"Suspects":"",
**23** "Time":"2018-10-30 13:17:38"
},
**33** { "Player":"IOS",
"Crime1":"",
"Crime2":"",
**33** "Crime3":"",
"Partners1":"",
"Partners2":"",
**23** "Partners3":"",
"Suspects":"",
**23** "Time":"2018-10-30 13:18:05"
},
**7c** { "Player":"Old Jay",
"Crime1":"",
"Crime2":"",
"Crime3":"",
"Partners1":"",
"Partners2":"",
"Partners3":"",
**34** "Suspects":"",
"Time":"2018-10-30 13:18:24"
},
**5b** { "Player":"Old Brenda",
"Crime1":"",
"Crime2":"",
"Crime3":"",
"Partners1":"",
**35** "Partners2":"",
"Partners3":"",
"Suspects":"",
**25** "Time":"2018-10-30 13:18:34"
}
]
} **0**
以下是生成该输出的PHP代码:
echo "\"data\":[\n";
$i=0;
while ($i < $num) {
$Player=mysqli_result($result,$i,"Player");
$Crime1=mysqli_result($result,$i,"Crime1");
$Crime2=mysqli_result($result,$i,"Crime2");
$Crime3=mysqli_result($result,$i,"Crime3");
$Partners1=mysqli_result($result,$i,"Partners1");
$Partners2=mysqli_result($result,$i,"Partners2");
$Partners3=mysqli_result($result,$i,"Partners3");
$Suspects=mysqli_result($result,$i,"Suspects");
$Time=mysqli_result($result,$i,"Time");
echo " {\n";
echo " \"Player\":\"$Player\",\n";
echo " \"Crime1\":\"$Crime1\",\n";
echo " \"Crime2\":\"$Crime2\",\n";
echo " \"Crime3\":\"$Crime3\",\n";
echo " \"Partners1\":\"$Partners1\",\n";
echo " \"Partners2\":\"$Partners2\",\n";
echo " \"Partners3\":\"$Partners3\",\n";
echo " \"Suspects\":\"$Suspects\",\n";
echo " \"Time\":\"$Time\"\n";
if ($i == $num-1)
echo " }\n";
else
echo " },\n";
$i++;
}
echo "]\n}";
调用它也可以安全地解决问题,但是我仍然对这种情况的发生感到惊讶。数字甚至不会在相同的语句之间插入,也不会以相等的间隔插入(除非总是在每个循环的第一个回声之前)。
谢谢。