我尝试从 AndroidStudio 中的 PHP 脚本解析 JSONArray。我从我的 PHP 脚本得到这个 JSON 响应: [{"0":"Firstname","meta_value":"Firstname"},{"0":"Lastname","meta_value":"Lastname"},{"valid":"1"},{"entered":"5"}] 现在我尝试解析 JSONArray 以获取值meta_value,所以我想获取“姓氏”和“名字”。
但我的代码中一定有错误,因为我得到了响应:Exception: No value for meta_value
public class SendPostRequest extends AsyncTask<String, Void, String> {
String data ="";
String dataParsed = "";
String singleParsed ="";
protected void onPreExecute(){}
protected String doInBackground(String... arg0) {
try {
URL url = new URL("https://sample.com/code2.php"); // here is your URL path
JSONObject postDataParams = new JSONObject();
postDataParams.put("sdata", scannedData);
Log.e("params",postDataParams.toString());
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(15000 /* milliseconds */);
conn.setConnectTimeout(15000 /* milliseconds */);
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(os, "UTF-8"));
writer.write(getPostDataString(postDataParams));
writer.flush();
writer.close();
os.close();
请不要将我的答案标记为重复,因为我搜索了 2 周但还没有找到答案!谢谢你:)
慕的地10843
相关分类