Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.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 Android在分析的字符0处输入的json结尾时出错_Php_Android_Json - Fatal编程技术网

Php Android在分析的字符0处输入的json结尾时出错

Php Android在分析的字符0处输入的json结尾时出错,php,android,json,Php,Android,Json,这是整个错误消息: error parsing data org.json.jsonexception end of input at character 0 of 这是我的全部代码: // JSON Node names public static final String TAG_SUCCESS = "success"; public static final String TAG_ID = "salesorderingcard_id"; public static String

这是整个错误消息:

    error parsing data org.json.jsonexception end of input at character 0 of
这是我的全部代码:

// JSON Node names
public static final String TAG_SUCCESS = "success";
public static final String TAG_ID = "salesorderingcard_id";
public static String TAG_CODE = "salesordercard_code";
public static final String TAG_LOCATION_TO = "location_to";
public static final String TAG_LOCATION_FROM = "location_from";
public final static String TAG_CUSTOMER = "customername";
public final static String TAG_SALESMAN = "salesmanname";


protected String doInBackground(String... args) {

            // getting updated data from EditTexts
            String salesordercard_code = etCode.getText().toString();
            String location_from = etFrom.getText().toString();
            String location_to = etTo.getText().toString();

            String customername = etCustomer.getText().toString();
            String salesmanname = etSalesman.getText().toString();

            Bundle extras = getIntent().getExtras();

            String salesorderingcard_id = extras.getString("salesorderingcard_id");;

            // Building Parameters
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair(TAG_ID, salesorderingcard_id));
            params.add(new BasicNameValuePair(TAG_CODE, salesordercard_code));
            params.add(new BasicNameValuePair(TAG_LOCATION_FROM, location_from));
            params.add(new BasicNameValuePair(TAG_LOCATION_TO, location_to));
            params.add(new BasicNameValuePair(TAG_CUSTOMER, customername));
            params.add(new BasicNameValuePair(TAG_SALESMAN, salesmanname));

            Log.d("Salesman", salesmanname);

            // sending modified data through http request
            // Notice that update salesorder url accepts POST method
            JSONObject json = jsonParser.makeHttpRequest(url_update_salesorder,
                    "POST", params);

            // check json success tag
            try {
                int success = json.getInt(TAG_SUCCESS);

                if (success == 1) {
                    // successfully updated
                    //Intent i = getIntent();
                    // send result code 100 to notify about Sales Order update
                    //setResult(100, i);
                    //finish();
                    Log.d("Update Successful", "Update Successful");
                } else {
                    // failed to update Sales Order
                    Log.d("Update failed", "Update failed");
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }
我试图用我的android测试应用程序在线更新我的记录,但我没能做到。我不知道怎么了,我真的需要你的帮助。非常感谢您的帮助

更新:

// JSON Node names
public static final String TAG_SUCCESS = "success";
public static final String TAG_ID = "salesorderingcard_id";
public static String TAG_CODE = "salesordercard_code";
public static final String TAG_LOCATION_TO = "location_to";
public static final String TAG_LOCATION_FROM = "location_from";
public final static String TAG_CUSTOMER = "customername";
public final static String TAG_SALESMAN = "salesmanname";


protected String doInBackground(String... args) {

            // getting updated data from EditTexts
            String salesordercard_code = etCode.getText().toString();
            String location_from = etFrom.getText().toString();
            String location_to = etTo.getText().toString();

            String customername = etCustomer.getText().toString();
            String salesmanname = etSalesman.getText().toString();

            Bundle extras = getIntent().getExtras();

            String salesorderingcard_id = extras.getString("salesorderingcard_id");;

            // Building Parameters
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair(TAG_ID, salesorderingcard_id));
            params.add(new BasicNameValuePair(TAG_CODE, salesordercard_code));
            params.add(new BasicNameValuePair(TAG_LOCATION_FROM, location_from));
            params.add(new BasicNameValuePair(TAG_LOCATION_TO, location_to));
            params.add(new BasicNameValuePair(TAG_CUSTOMER, customername));
            params.add(new BasicNameValuePair(TAG_SALESMAN, salesmanname));

            Log.d("Salesman", salesmanname);

            // sending modified data through http request
            // Notice that update salesorder url accepts POST method
            JSONObject json = jsonParser.makeHttpRequest(url_update_salesorder,
                    "POST", params);

            // check json success tag
            try {
                int success = json.getInt(TAG_SUCCESS);

                if (success == 1) {
                    // successfully updated
                    //Intent i = getIntent();
                    // send result code 100 to notify about Sales Order update
                    //setResult(100, i);
                    //finish();
                    Log.d("Update Successful", "Update Successful");
                } else {
                    // failed to update Sales Order
                    Log.d("Update failed", "Update failed");
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }
我得到了一个NULLPOINTERCEPTION

 int success = json.getInt(TAG_SUCCESS);
响应是:org.apache.http.conn。EOFSENSORINPUTSTREAM@417dbcf8试试这个

class AsyncHttpRequest extends AsyncTask<String, Void, String> {

        @Override
        protected String doInBackground(String... urls) {

            try {
                if (!isGetMethod) {
                    HttpPost httppost = new HttpPost(urls[0]);
                    httpclient = new DefaultHttpClient();

                    HttpConnectionParams.setConnectionTimeout(
                            httpclient.getParams(), 30000);

                    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

                    for (String key : map.keySet()) {
                        System.out.println(key + "  < === >  " + map.get(key));

                        nameValuePairs.add(new BasicNameValuePair(key, map
                                .get(key)));
                    }

                    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                    ActivityManager manager = (ActivityManager) activity
                            .getSystemService(Context.ACTIVITY_SERVICE);

                    if (manager.getMemoryClass() < 25) {
                        System.gc();
                    }
                    HttpResponse response = httpclient.execute(httppost);

                    String responseBody = EntityUtils.toString(response
                            .getEntity());

                    return responseBody;

                } else {
                    httpclient = new DefaultHttpClient();

                    HttpConnectionParams.setConnectionTimeout(
                            httpclient.getParams(), 30000);
                    HttpGet httpGet = new HttpGet(urls[0]);

                    HttpResponse httpResponse = httpclient.execute(httpGet);
                    HttpEntity httpEntity = httpResponse.getEntity();

                    String responseBody = EntityUtils.toString(httpEntity);
                    return responseBody;
                }
            } catch (Exception e) {
                e.printStackTrace();
            } catch (OutOfMemoryError oume) {
                System.gc();

            } finally {
                if (httpclient != null)
                    httpclient.getConnectionManager().shutdown();

            }

            return null;

        }

        @Override
        protected void onPostExecute(String response) {

            //here is your response

        }
    }
类AsyncHttpRequest扩展了AsyncTask{
@凌驾
受保护的字符串doInBackground(字符串…URL){
试一试{
如果(!isGetMethod){
HttpPost HttpPost=新的HttpPost(URL[0]);
httpclient=新的DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(
httpclient.getParams(),30000);
List nameValuePairs=新的ArrayList();
for(字符串键:map.keySet()){
System.out.println(key+“<=>”+map.get(key));
添加(新的BasicNameValuePair(键,映射
.get(key));
}
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
ActivityManager manager=(ActivityManager)活动
.getSystemService(Context.ACTIVITY\u服务);
if(manager.getMemoryClass()<25){
gc();
}
HttpResponse response=httpclient.execute(httppost);
String ResponseBy=EntityUtils.toString(响应
.getEntity());
返回响应体;
}否则{
httpclient=新的DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(
httpclient.getParams(),30000);
HttpGet HttpGet=新的HttpGet(URL[0]);
HttpResponse HttpResponse=httpclient.execute(httpGet);
HttpEntity HttpEntity=httpResponse.getEntity();
String ResponseBy=EntityUtils.toString(httpEntity);
返回响应体;
}
}捕获(例外e){
e、 printStackTrace();
}捕获(OutOfMemoryError oume){
gc();
}最后{
if(httpclient!=null)
httpclient.getConnectionManager().shutdown();
}
返回null;
}
@凌驾
受保护的void onPostExecute(字符串响应){
//这是你的回答
}
}
通过在InputStream上调用toString(),可以获得对象的哈希代码。试试这个:

Log.d("response", EntityUtils.toString(httpEntity));

我认为您的回复将不包含有效的json格式!!!!!张贴你的response@Hardik我已经添加了json响应,请检查它,因为响应不是有效的json格式,所以出现了异常!分析字符0处输入的数据org.json.jsonexception结尾时出错of@Hardik那么我必须做些什么来解决这个问题呢?您好,我尝试了这个,我得到了一个错误:内容已经被使用了将它替换到'is=httpEntity.getContent();'内容只能使用一次。
Log.d("response", EntityUtils.toString(httpEntity));