Php Android JSON错误空指针
我使用JSON来获取sql中的所有问题 我用同样的逻辑来获取其他数据 但是,当我尝试记录JSON对象或打印它时。。我有一个空点异常Php Android JSON错误空指针,php,android,json,Php,Android,Json,我使用JSON来获取sql中的所有问题 我用同样的逻辑来获取其他数据 但是,当我尝试记录JSON对象或打印它时。。我有一个空点异常 List<NameValuePair> params = new ArrayList<NameValuePair>(); JSONObject json = jsonParser.getJson("http://10.0.2.2/qm/perguntas.php", "GET", params); Log.d("All
List<NameValuePair> params = new ArrayList<NameValuePair>();
JSONObject json = jsonParser.getJson("http://10.0.2.2/qm/perguntas.php", "GET", params);
Log.d("All Products: ", json.toString());
List params=new ArrayList();
JSONObject json=jsonParser.getJson(“http://10.0.2.2/qm/perguntas.php“,”GET“,params);
Log.d(“所有产品:,json.toString());
以及php代码:
<?php
$response = array();
require_once 'include/DB_Connect.php';
$db = new DB_Connect();
$result = mysql_query("SELECT * FROM perguntas") or die(mysql_error());
if (mysql_num_rows($result) > 0) {
$response["perguntas"] = array();
while ($row = mysql_fetch_array($result)) {
$pergunta = array();
$pergunta["uid"] = $row["uid"];
$pergunta["pergunta"] = $row["pergunta"];
$pergunta["remetente"] = $row["remetente"];
$pergunta["para"] = $row["para"];
$pergunta["anonimo"] = $row["anonimo"];
//$pergunta["resposta"] = $row["resposta"];
array_push($response["perguntas"], $pergunta);
}
$response["success"] = 1;
echo json_encode($response);
} else {
$response["success"] = 0;
$response["message"] = "Sem perguntas";
echo json_encode($response);
}
?>
您是否检查过URLhttp://10.0.2.2/qm/perguntas.php
在代码中测试之前是否工作?尝试按住CTRL键并单击鼠标左键,检查结果是否也在代码之外获取(这将在Eclipse中打开一个Web浏览器选项卡)。到目前为止,我看不出有什么问题。既不使用PHP脚本,也不使用Android代码。需要更多上下文什么类型的jsonParser?