小编sig*_*onf的帖子

Volley post请求中的JSON格式无效

我想通过

 data={"process" : "ExampleProcess", "phone" : "123456"}
Run Code Online (Sandbox Code Playgroud)

作为一个截击请求,到目前为止,我已经设法创建一个(非常基本的)方法,将所需的信息发送到服务器,但我得到一个失败的响应.

我将日志添加到我可以看到的程序中

ERROR :: com.android.volley.ParseError:org.json.JSONException:字符2处的输入结束

但我认为这与我试图发送信息的方式有关.经过调试,我也意识到我收到了错误信息

方法抛出'java.lang.NullPointerException'异常.无法评估org.json.JSONObject.toString();

我不知道该做什么,即使我改变了:

        total.put("data", data.toString());
Run Code Online (Sandbox Code Playgroud)

        total.put("data", data);
Run Code Online (Sandbox Code Playgroud)

错误将持续存在.在这一点上,我不知道如何向我的URL发送正确的JSON post请求(已从示例btw中取出)

public void volleyConnector(String url) {
        final JSONObject data = new JSONObject();
        final JSONObject total = new JSONObject();


        try {

            data.put("process", "ExampleProcess");
            data.put("phone"  , "123456789");
            total.put("data", data.toString());

        } catch(JSONException e) {

            Log.v("JSON ERROR: ", e.toString());
        }


         JsonObjectRequest jsonObjectRequest = new JsonObjectRequest( url, total, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                Log.v("--------------","---------------------------");
                Log.v("RESPONSE: ", "-----> " + response.toString()); …
Run Code Online (Sandbox Code Playgroud)

java post android json android-volley

1
推荐指数
1
解决办法
536
查看次数

标签 统计

android ×1

android-volley ×1

java ×1

json ×1

post ×1