gpt4 book ai didi

java - 检索错误数据

转载 作者:可可西里 更新时间:2023-11-01 11:43:06 24 4
gpt4 key购买 nike

这是MySQL数据(表工作详情)

enter image description here

通过以下代码检索的数据。注意到我想检索除 idtwd 之外的所有内容。

 private void showForce(String json) {
try {
JSONObject jsonObject = new JSONObject(json);
JSONArray result = jsonObject.getJSONArray(Configs.TAG_JSON_ARRAY);
JSONObject c = result.getJSONObject(0);
String project = c.getString(Configs.TAG_PROJECT).trim();
RetrieveProject(project);
String description = c.getString(Configs.TAG_WORKDESCRIPTION).trim();
int per = c.getInt(Configs.TAG_PERCENTAGE);
String in=c.getString(Configs.TAG_IN).trim();
String time[]=in.split(":", 3);
String time1=time[0]+":"+time[1];
String out=c.getString(Configs.TAG_OUT).trim();
String timeOut[]=out.split(":", 3);
String timeout=timeOut[0]+":"+timeOut[1];
seekBar.setProgress(per);
progressText.setText("Covered:" + "" + seekBar.getProgress() + "/" + seekBar.getMax());
String From=c.getString(Configs.TAG_From).trim();
String To=c.getString(Configs.TAG_To).trim();
String Mil=c.getString(Configs.TAG_Mileage).trim();
String Hotel=c.getString(Configs.TAG_Hotel).trim();
String Toll=c.getString(Configs.TAG_Toll).trim();
String Business=c.getString(Configs.TAG_Business).trim();

TimeIn.setText(time1);
TimeOut.setText(timeout);
Description.setText(description);
mileage.setText(Mil);
hotel.setText(Hotel);
business.setText(Business);
toll.setText(Toll);
travelFrom.setText(From);
travelTo.setText(To);

} catch (JSONException e) {
e.printStackTrace();
}

PhP

<?php
define('HOST','localhost');
define('USER','spiral69_wp178');
define('PASS','q1w2e3r4');
define('DB','spiral69_androiddb');

$con = mysqli_connect(HOST,USER,PASS,DB) or die('unable to connect');

$id=$_GET['id'];

$sql = "select * from work_details WHERE id= '". $id."'";

$res = mysqli_query($con,$sql);

$result=array();

while($row=mysqli_fetch_array($res)){
array_push($result,array('id'=>$row[0],'project'=>$row[1],'work_description'=>$row[2],'percentage'=>$row[3],'timeIn'=>$row[4],
'timeOut'=>$row[5],'travel_From'=>$row[6],'travel_To'=>$row[7],'mileage'=>$row[8],'hotel_accom'=>$row[9],'toll'=>$row[10],'business_expenses'=>$row[11]));
}

echo (json_encode(array("result"=>$result)));

mysqli_close($con);

?>

Project,Description,TimeIn,TimeOut,per 显示正确,但 From、To、Mil、Hotel、Toll、Business 不正确。

这是我在 setText 中得到的输出。(不正确)

 travelFrom.setText(From); I get 63 (twd column)
travelTo.setText(To); I get df (travel_from column)
mileage.setText(Mil); I get a....

最佳答案

只是当您在 PHP 脚本中的 json 对象中设置数据时,您错过了“twd”列...“travel_from”的索引是 7 而不是 6,之后的其他字段同样适用!! !

关于java - 检索错误数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35378245/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com