Java 截击分析错误org.json.JSONException:输入结束,位于的字符0处

Java 截击分析错误org.json.JSONException:输入结束,位于的字符0处,java,android,android-intent,jax-rs,jax-ws,Java,Android,Android Intent,Jax Rs,Jax Ws,一,;我正在开发一个android应用程序和JavaJAX的RESTfulWeb服务。当我的应用程序在服务上发送json时,发生该错误。如果我从Restful客户端浏览器服务发送json成功接收数据,但无法从android应用程序接收。。。。 我的应用程序和服务代码在这里。这是我的android活动 public class feedback extends SameCodeClass implements View.OnClickListener { String f_name, f_mobi

一,;我正在开发一个android应用程序和JavaJAX的RESTfulWeb服务。当我的应用程序在服务上发送json时,发生该错误。如果我从Restful客户端浏览器服务发送json成功接收数据,但无法从android应用程序接收。。。。 我的应用程序和服务代码在这里。这是我的android活动

public class feedback extends SameCodeClass implements View.OnClickListener {
String f_name, f_mobile, f_description, f_ratVel;
double f_rating;
RequestQueue requestQueue;
String responseServer;
feedbackModel fbModel;

private String TAG = feedback.class.getSimpleName();
private String tag_json_obj = "jobj_req", tag_json_arry = "jarray_req";
private ProgressDialog pDialog;
EditText name, mobile, des;
TextView rating;
RatingBar ratingBar;
Button submint_fb;

protected void onCreate(Bundle b) {
    super.onCreate(b);
    setContentView(R.layout.feedback);

    Initialize();
    addListenerOnRatingBar();
}

protected void Initialize() {
    name = (EditText) findViewById(R.id.name);
    mobile = (EditText) findViewById(R.id.mobile);
    des = (EditText) findViewById(R.id.des);
    rating = (TextView) findViewById(R.id.rating);
    ratingBar = (RatingBar) findViewById(R.id.ratingBar);
    submint_fb = (Button) findViewById(R.id.fsbutton);

    submint_fb.setOnClickListener(this);

    pDialog = new ProgressDialog(this);
    pDialog.setMessage("Loading...");
    pDialog.setCancelable(false);

    requestQueue = Volley.newRequestQueue(this);


}


private void showProgressDialog() {
    if (!pDialog.isShowing())
        pDialog.show();
}

private void hideProgressDialog() {
    if (pDialog.isShowing())
        pDialog.hide();
}

protected void setValues() {
    f_name = name.getText().toString();
    f_mobile = mobile.getText().toString();
    f_description = des.getText().toString();
    f_ratVel = rating.getText().toString();
    f_rating = Double.parseDouble(f_ratVel);

    if (f_name != null && f_mobile != null && f_description != null && f_rating != 0.0) {
        //   Toast.makeText(getBaseContext(),f_name+","+f_mobile+","+f_description+","+f_rating,Toast.LENGTH_LONG).show();
             createJsonObj();

    } else {

        if (f_name.isEmpty()) {
            Toast.makeText(getBaseContext(), "Enter Name First.", Toast.LENGTH_LONG).show();
        } else if (f_mobile.isEmpty()) {
            Toast.makeText(getBaseContext(), "Enter Mobile Number.", Toast.LENGTH_LONG).show();
        } else if (f_description.isEmpty()) {
            Toast.makeText(getBaseContext(), "Enter Your Message.", Toast.LENGTH_LONG).show();
        } else if (f_ratVel.isEmpty()) {
            Toast.makeText(getBaseContext(), "0.0 Rating Not Acceptable.", Toast.LENGTH_LONG).show();
        }
    }


}


//  Volley Json Request...

private void createJsonObj() {


    String url = "http://192.168.23.1:8080/RESTfulExample/rest/file/feedback";
    showProgressDialog();


    Map<String, String> jsonParams = new HashMap<String, String>();
    //jsonParams.put("param1", youParameter);
    jsonParams.put("name", f_name);
    jsonParams.put("mobile", f_mobile);
    jsonParams.put("description", f_description);
    jsonParams.put("rating", f_ratVel);

    JsonObjectRequest myRequest = new JsonObjectRequest(
            Request.Method.POST,
            url,
            new JSONObject(jsonParams),

            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    // verificationSuccess(response);
                    Toast.makeText(getBaseContext(), response.toString(), Toast.LENGTH_LONG).show();
                    hideProgressDialog();
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    //  verificationFailed(error);
                    VolleyLog.d(TAG, "Error: " + error.getMessage());
                    hideProgressDialog();

                    NetworkResponse networkResponse = error.networkResponse;
                    if (networkResponse != null) {
                        Log.e("Volley", "Error. HTTP Status Code:" + networkResponse.statusCode);
                    }

                    if (error instanceof TimeoutError) {
                        Log.e("Volley", "TimeoutError");
                    } else if (error instanceof NoConnectionError) {
                        Log.e("Volley", "NoConnectionError");
                    } else if (error instanceof AuthFailureError) {
                        Log.e("Volley", "AuthFailureError");
                    } else if (error instanceof ServerError) {
                        Log.e("Volley", "ServerError");
                    } else if (error instanceof NetworkError) {
                        Log.e("Volley", "NetworkError");
                    } else if (error instanceof ParseError) {
                        Log.e("Volley", "Parse Error: "+ error.getMessage());
                    }

                }
            }) {

        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            HashMap<String, String> headers = new HashMap<String, String>();
            headers.put("Content-Type", "application/json; charset=utf-8");
            // headers.put("User-agent", "My useragent");
            return headers;
        }

        @Override
        public Priority getPriority() {
            return Priority.IMMEDIATE;
        }
    };

         requestQueue.add(myRequest);


}


public void addListenerOnRatingBar() {

    ratingBar = (RatingBar) findViewById(R.id.ratingBar);
    rating = (TextView) findViewById(R.id.rating);

    //if rating value is changed,
    //display the current rating value in the result (textview) automatically
    ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
        public void onRatingChanged(RatingBar ratingBar, float rat,
                                    boolean fromUser) {

            rating.setText(String.valueOf(rat));

        }
    });
}

public void onClick(View v) {
    switch (v.getId()) {
        case R.id.fsbutton: {
            if(isOnline()){
                setValues();
           //     requestData("http://192.168.23.1:8080/RESTfulExample/rest/file/show");

            }else{
                Toast.makeText(this,"Network isn't available", Toast.LENGTH_LONG).show();
            }


        }
    }

}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    if (id != R.id.fdb) {
        DealMenu(id);
    }

    return super.onOptionsItemSelected(item);
}


@Override
public void onBackPressed() {
    BackButtonHandle();
    return;
}
protected boolean isOnline() {
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    if (netInfo != null && netInfo.isConnectedOrConnecting()) {
        return true;
    } else {
        return false;
    }
}

}
我的反馈模型在这里

package com.live.rest.Model;
import java.io.Serializable;
public class newFeedModel implements Serializable{

public String id;
public String name;
public String mobile;
public String description;
public String rating;

public void setId(String id) {
    this.id = id;
}
public newFeedModel() {
    super();
}

public newFeedModel(String name, String mobile, String description, String rating) {
    super();
    this.name = name;
    this.mobile = mobile;
    this.description = description;
    this.rating = rating;
}

public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public String getMobile() {
    return mobile;
}
public void setMobile(String mobile) {
    this.mobile = mobile;
}
public String getDescription() {
    return description;
}
public void setDescription(String description) {
    this.description = description;
}
public String getRating() {
    return rating;
}
public void setRating(String rating) {
    this.rating = rating;
}
}

您将得到一个空白/空的响应。您不会得到异常,但json编码的文本为空

检查Post Request/Get Request-您在服务器端使用的内容

通过调试检查API是否返回有效的json

检查响应是否应该是有效的json。您可以在下面的链接中检查json是否有效。

检查是否已将以下权限添加到Android清单中

<uses-permission android:name = "android.permission.INTERNET"/>

检查您是否有工作的internet连接

参考链接:

,

Happy编码

<uses-permission android:name = "android.permission.INTERNET"/>