Php 为什么我的数据没有出来?
这是我的班级档案Php 为什么我的数据没有出来?,php,android,android-studio,Php,Android,Android Studio,这是我的班级档案 public class Config { public static final String DATA_URL = "http://192.168.1.2/retrieveone.php?id="; public static final String KEY_NAME = "BusinessName"; public static final String KEY_AmountTotal = "AmountTotal"; public st
public class Config {
public static final String DATA_URL = "http://192.168.1.2/retrieveone.php?id=";
public static final String KEY_NAME = "BusinessName";
public static final String KEY_AmountTotal = "AmountTotal";
public static final String KEY_RT = "RequiredTotal";
public static final String KEY_MT = "MaxTotal";
public static final String JSON_ARRAY = "result";
}
“”工作得非常好,但该值没有显示在我的setText中。
我是Android Studio的初学者。感谢您的帮助。提前谢谢
编辑:
这是我的错误。无法将java.lang.String类型的值连接转换为JSONObject首先声明一个带有响应文本的json数组,然后创建一个JSONObject。 试试这个
?php
if($_SERVER['REQUEST_METHOD']=='GET'){
$id = $_GET['id'];
require_once('conn.php');
$sql = "SELECT * FROM business WHERE BusinessID='".$id."'";
$r = mysqli_query($conn,$sql);
$res = mysqli_fetch_array($r);
$result = array();
array_push($result,array(
"BusinessName"=>$res['BusinessName'],
"AmountTotal"=>$res['AmountTotal'],
"RequiredTotal"=>$res['RequiredTotal'],
"MaxTotal"=>$res['MaxTotal']
)
);
echo json_encode(array("result"=>$result));
mysqli_close($conn);
}
在访问类“Config”文件之前,是否导入/包括该类文件
请将您的代码放入try/catch块并输出异常以获取更多信息。您能显示JSONObject的输出吗?@Mahdi.Pishguy您标记了错误的人我不是发布问题的人:)@HahaHehe您解析的json不正确,请在
e.printStackTrace()之后添加Log.e(“error”,e.getMessage())
;代码>并再次运行应用程序以查看在上发生的情况Logcat@HemantSangle很抱歉,先生,无法将java.lang.String类型的thanksValue连接转换为JSONObjectValue,无法将java.lang.String类型的连接转换为JSONObjectValue,原因是在编写字符串“response”时添加了一些不需要的字符。请把它格式化好。是否可以输出响应字符串??会有帮助的顺便问一下,我该怎么做?我是Android Studio的初学者,不知道如何输出响应字符串。提前感谢您提供此链接[此处]{“结果”:[{“商业名称”:“KachangPuteh”,“总数”:“100”,“所需总数”:“200”,“最大总数”:“500”}]}
?php
if($_SERVER['REQUEST_METHOD']=='GET'){
$id = $_GET['id'];
require_once('conn.php');
$sql = "SELECT * FROM business WHERE BusinessID='".$id."'";
$r = mysqli_query($conn,$sql);
$res = mysqli_fetch_array($r);
$result = array();
array_push($result,array(
"BusinessName"=>$res['BusinessName'],
"AmountTotal"=>$res['AmountTotal'],
"RequiredTotal"=>$res['RequiredTotal'],
"MaxTotal"=>$res['MaxTotal']
)
);
echo json_encode(array("result"=>$result));
mysqli_close($conn);
}
try {
JSONArray result = new JSONArray(response);
JSONObject stallsData = result.getJSONObject(0);
name = stallsData.getString(Config.KEY_NAME);
AmountTotal = stallsData.getString(Config.KEY_AmountTotal);
MaxTotal = stallsData.getString(Config.KEY_MT);
RequiredTotal = stallsData.getString(Config.KEY_RT);
} catch (JSONException e) {
e.printStackTrace();
}