分析dataorg.json.JSONException时出错:java.lang.String类型的值
我正试图为我的论文制作android食品订单,因为这个错误,我的时间不多了: logcat上的错误: 分析dataorg.json.JSONException时出错:无法将值转换为JSONObject org.json.JSONException:JSONObject的值 下面是我的JSONParser:分析dataorg.json.JSONException时出错:java.lang.String类型的值,java,php,android,mysql,json,Java,Php,Android,Mysql,Json,我正试图为我的论文制作android食品订单,因为这个错误,我的时间不多了: logcat上的错误: 分析dataorg.json.JSONException时出错:无法将值转换为JSONObject org.json.JSONException:JSONObject的值 下面是我的JSONParser: package com.makanan.restotradisional; import java.io.BufferedReader; import java.io.IOException
package com.makanan.restotradisional;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.json.JSONObject;
import android.util.Log;
public class JSONParser {
static InputStream is = null;
static JSONObject jObj = null;
static String json = "";
public JSONParser() {
}
// fungsi abil json url lewat method HTTP POST atau GET
public JSONObject makeHttpRequest(String url, String method,
List<NameValuePair> params) {
try {
if (method == "POST") {
// jika request method adalah 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") {
// jika request method adalah 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 {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data" + e.toString());
e.printStackTrace();
}
return jObj;
}
}
这是我的PHP和Java:
这是我在phpmyadmin上的数据库:
请帮助我从php文件中删除任何语句或echo语句,但用于传递json的语句除外
在浏览器中检查文件的输出,删除除json以外的所有不需要的内容。请打印并检查字符串json的格式是否符合JSONObject构造函数的预期。根据文档,构造JSONObject的有效json字符串应该是-一个以{左大括号开始,以}右大括号结束的字符串
请参阅。进入JSONParser内部,这样您就可以在logcat中看到php带来了什么。可能是php错误
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
//This line is what u need to add
Log.d("Whats wrong?", json.toString());
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
请提供在JSONObject构造函数中传递的字符串