Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 即使单个数据为null,也无法获得JsonResponse_Php_Android_Mysql - Fatal编程技术网

Php 即使单个数据为null,也无法获得JsonResponse

Php 即使单个数据为null,也无法获得JsonResponse,php,android,mysql,Php,Android,Mysql,这是来自PHP的JsonResponse。 我无法在android studio中使用这些响应获取任何响应,因为这些响应中存在空数据。 如果不存在空数据,则response.getString具有所有这些数据,但response.getString由于空数据而没有响应。 有什么问题吗 {"futsal_id":"59", "description":[{ "futsal_id":"59", "futsal_desc":"This is great futsal"}],

这是来自PHP的JsonResponse。 我无法在android studio中使用这些响应获取任何响应,因为这些响应中存在空数据。 如果不存在空数据,则response.getString具有所有这些数据,但response.getString由于空数据而没有响应。 有什么问题吗

  {"futsal_id":"59",
    "description":[{
    "futsal_id":"59",
    "futsal_desc":"This is great futsal"}],

    "features":[{"futsal_id":"59","futsal_feat":"free 4 bottles of water"}],
    "dimension":null,
    "no_of_futsal":null,
    "opening_hrs":null,
    "price_weekdays_price1":[{
            "futsal_id":"59",
            "price_id":"1",
            "start_time":"6am",
            "end_time":"10am",
            "price":"1000"}],
    "price_weekdays_price2":[{
            "futsal_id":"59",
            "price_id":"2",
            "start_time":"10am",
            "end_time":"3pm",
            "price":"1200"}],
    "price_weekdays_price3":[{
            "futsal_id":"59",
            "price_id":"3",
            "start_time":"3pm",
            "end_time":"9pm",
            "price":"1300"}],
    "price_weekend_price1":null,
            "price_weekend_price2":null,
            "price_weekend_price3":null,
    "images":[],
    "image_count":0,
    "news":null}
替换您的代码

    class ShowResult extends AsyncTask<Void, Void, String[]> {

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pd.show();
    }

    @Override
    protected void onPostExecute(String[] aVoid) {
        super.onPostExecute(aVoid);
        pd.cancel();
        txt.setText(result[0]);
      }

    @Override
    protected String[] doInBackground(Void... params) {
        try {
            Log.d("sssssssssssssss", "sadf");

            URL url = new URL("http://futsalgroove.s4generation.com/app/android_c/show_details/");
            HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
            urlConnection.setDoOutput(true);
            urlConnection.setRequestMethod("POST");

            String urlParameters = "id=" + bundle.getString("id");
            //sending the parameter using DataOutputStream
            DataOutputStream wr = new DataOutputStream(urlConnection.getOutputStream());
            wr.writeBytes(urlParameters);
            wr.flush();
            wr.close();

            //Reading the data or response from the PHP file
            BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));

            Log.d("sssssssssssssss", "iii" + in);
            String inputLine;
            StringBuffer response = new StringBuffer();

            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
                Log.d("Detail Outputss", inputLine);
            }
            in.close();
            //Using the JasonObject from php
            Log.d("Detail Outputsss", "" + response.toString());

            JSONObject json = new JSONObject(response.toString());

            JSONArray description = json.getJSONArray("description");
            JSONObject descObj = description.getJSONObject(0);

            result[0] =  descObj.getString("futsal_desc");
            Log.d("DetailOut","" + result[0]);
     }

       } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (JSONException e) {

        }
        return result;
    }
}

也许这会奏效。对于JObject,请在顶部使用Newtonsoft.Json.Linq

JObject json = JObject.Parse(response.toString());
JArray description = (JArray)json["description"];
JObject descObj = (JObject)description[0];
result[0] = descObj["futsal_desc"].ToString();
Log.d("DetailOut","" + result[0]);

请添加更多细节并格式化json代码,使其更易于阅读,不要使用android。在浏览器中加载url并检查json。拥有json解析器扩展会有所帮助。如果没有,您可以使用developer console.Log.dDetail Outputsss,+response.toString;它打印的内容…?响应中没有显示任何内容。toString如果我的响应中没有空值,则response.toString具有所有值。。response.toString由于为null而未获取任何值data@Nabin您能打印并检查urlConnection.getResponseCode提供了什么吗?
JObject json = JObject.Parse(response.toString());
JArray description = (JArray)json["description"];
JObject descObj = (JObject)description[0];
result[0] = descObj["futsal_desc"].ToString();
Log.d("DetailOut","" + result[0]);
using Newtonsoft.Json.Linq;