Java 分析字符0处输入的数据org.json.jsonexception结尾时出错
我一整天都在查看我的代码,找不到为什么会发生这种情况(或者为什么它实际上没有从MySQL服务器返回它应该返回的结果)。 希望一双新的眼睛能找到原因 Jsonparser类Java 分析字符0处输入的数据org.json.jsonexception结尾时出错,java,php,android,mysql,json,Java,Php,Android,Mysql,Json,我一整天都在查看我的代码,找不到为什么会发生这种情况(或者为什么它实际上没有从MySQL服务器返回它应该返回的结果)。 希望一双新的眼睛能找到原因 Jsonparser类 public class JSONParser { static InputStream is = null; static JSONObject jObj = null; static String json = ""; // constructor public JSONPars
public class JSONParser {
static InputStream is = null;
static JSONObject jObj = null;
static String json = "";
// constructor
public JSONParser() {
}
// function get json from url
// by making HTTP POST or GET method
public JSONObject makeHttpRequest(String url, String method,
List<NameValuePair> params) {
// Making HTTP request
try {
// check for request method
if(method == "POST"){
// request method is POST
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
}else if(method == "GET"){
// request method is GET
DefaultHttpClient httpClient = new DefaultHttpClient();
String paramString = URLEncodedUtils.format(params, "utf-8");
url += "?" + paramString;
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
// try parse the string to a JSON object
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
// return JSON String
return jObj;
}
}
来自PHP的错误
PHP Parse error: syntax error, unexpected T_BOOLEAN_AND, expecting ',' or ')' in /home/sites/pmclient.co.uk/public_html/dadgapp/get_user_details.php on line 19
您在:PHP代码中的行。您忘记了“;”in:
PHP代码中的行。提示的可能重复:如果只有
POST
和GET
有意义,那么如果你得到了其他东西,你就不应该继续。不要吞下异常-它真的没有帮助;它只是推迟了一个错误。可能是UTF-8错误?与BOM有关,或者是接近某个问题。@Trollo忘记说POST方法了d工作正常,只有当我执行上述GET do it error Out时,您的PHP服务器的日志会说什么?提示的可能重复:如果只有POST
和GET
有意义,那么如果您得到其他东西,您就不应该继续。不要吞下异常-它真的没有帮助;它只是延迟了一个错误。可能是UTF-8错误?与BOM或ne有关ar somethink with issue。@trololo忘了说POST方法工作正常,只有当我做了上面的GET do it error Out时,你的PHP服务器的日志会说什么?谢谢,但是在做了更改之后,我仍然会收到错误,要尝试获取另一个日志还有一些语法错误,但最终解决了,谢谢Guysys,尽管我需要做my应用程序更加健壮,因为如果找不到用户,它会崩溃,但至少它现在可以为那里的用户工作。谢谢。但是在做了更改之后,我仍然得到了错误,要尝试获取另一个日志。还有一些语法错误,但最终解决了。谢谢guysyes,尽管我需要让我的应用程序更加健壮如果找不到用户,则崩溃,但至少它现在对存在的用户有效
<?php
/*
* Following code will get single product details
* A product is identified by product id (pid)
*/
// array for JSON response
$response = array();
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
// check for post data
if (isset($_GET['email'] && isset($_GET['password')) {
$email = $_GET['email'];
$password = $_GET['password'];
// get a product from products table
$result = mysql_query("SELECT * FROM profiles_profiles WHERE ProfileEmail = '$email' AND ProfilePassword = '$password'");
if (!empty($result)) {
// check for empty result
if (mysql_num_rows($result) > 0) {
$result = mysql_fetch_array($result);
$product = array();
$product["ProfileID"] = $result["ProfileID"];
// success
$response["success"] = 1;
// user node
$response["product"] = array();
array_push($response["product"], $product);
// echoing JSON response
echo json_encode($response);
} else {
// no product found
$response["success"] = 0;
$response["message"] = "No user found";
// echo no users JSON
echo json_encode($response);
}
} else {
// no product found
$response["success"] = 0;
$response["message"] = "No user found";
// echo no users JSON
echo json_encode($response);
}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
// echoing JSON response
echo json_encode($response);
}
?>
08-18 18:43:55.573: E/JSON Parser(16008): Error parsing data org.json.JSONException: End of input at character 0 of
08-18 18:43:55.573: W/dalvikvm(16008): threadid=13: thread exiting with uncaught exception (group=0x41515450)
08-18 18:43:55.584: E/AndroidRuntime(16008): FATAL EXCEPTION: AsyncTask #1
08-18 18:43:55.584: E/AndroidRuntime(16008): java.lang.RuntimeException: An error occured while executing doInBackground()
08-18 18:43:55.584: E/AndroidRuntime(16008): at android.os.AsyncTask$3.done(AsyncTask.java:299)
08-18 18:43:55.584: E/AndroidRuntime(16008): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
08-18 18:43:55.584: E/AndroidRuntime(16008): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
08-18 18:43:55.584: E/AndroidRuntime(16008): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
08-18 18:43:55.584: E/AndroidRuntime(16008): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
08-18 18:43:55.584: E/AndroidRuntime(16008): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
08-18 18:43:55.584: E/AndroidRuntime(16008): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
08-18 18:43:55.584: E/AndroidRuntime(16008): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
08-18 18:43:55.584: E/AndroidRuntime(16008): at java.lang.Thread.run(Thread.java:856)
08-18 18:43:55.584: E/AndroidRuntime(16008): Caused by: java.lang.NullPointerException
08-18 18:43:55.584: E/AndroidRuntime(16008): at com.test.app.LogIn$GetUserDetails.doInBackground(LogIn.java:149)
08-18 18:43:55.584: E/AndroidRuntime(16008): at com.test.app.LogIn$GetUserDetails.doInBackground(LogIn.java:1)
08-18 18:43:55.584: E/AndroidRuntime(16008): at android.os.AsyncTask$2.call(AsyncTask.java:287)
08-18 18:43:55.584: E/AndroidRuntime(16008): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
08-18 18:43:55.584: E/AndroidRuntime(16008): ... 5 more
PHP Parse error: syntax error, unexpected T_BOOLEAN_AND, expecting ',' or ')' in /home/sites/pmclient.co.uk/public_html/dadgapp/get_user_details.php on line 19
$password = $_GET['password']