android - 为什么我得到空的 json 结果

标签 android json node.js

我正在尝试发送包含 2 个字段(用户和通行证)的帖子消息。

处理帖子的node.js(只是打印代码,不是所有功能):

app.post('/login.html', function (req, res) {

    log.info("Got: " , req.body);
    userName = req.body.name;
    pass = req.body.pass;
}

Android 应用程序看起来:

Network network = new BasicNetwork(new HurlStack());

// Instantiate the RequestQueue with the cache and network.
mRequestQueue = new RequestQueue(cache, network);

// Start the queue
mRequestQueue.start();

JsonPost(mRequestQueue);

JsonPost 方法看起来:

String url = getResources().getString(R.string.json_get_url);
Map<String, String> jsonParams = new LinkedHashMap<String, String>();

try {
    // adding some keys
    jsonParams.put("name", "root");
    jsonParams.put("pass", "123456");

} catch (Exception ex) {
    ex.printStackTrace();
}

// Initialize a new JsonObjectRequest instance
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(
    Request.Method.POST, url, new JSONObject(jsonParams),
    new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {

            System.out.println(response.toString());
        }
    },
    new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            System.out.println(error.toString());
        }
    }
)

我收到 {}(node.js 中的空 json 输出:GOT:{})

我看了这篇文章:(但没有找到答案) Getting Empty JSON response

为什么我得到空的 json 正文,如何修复它?

最佳答案

也许您发布的代码不完整,但我们应该使用以下行:

mRequestQueue.add(jsonObjectRequest);

所以请检查一下。

关于android - 为什么我得到空的 json 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52473744/

相关文章:

javascript - 如何在 json 值中使用一些 html 元素标签

javascript - 在sequelize中查询两个表

java - Android给出线性布局标签

ios - Restkit-如何在表格 View 中显示 json 数据

android - onContextItemSelected 没有被调用

php - 如何在yii2中进行Json编码?

javascript - 如何使用 Protractor 搜索类、在类中查找 p 标签并验证其某些文本?

node.js - Telegram 客户端 API。如何找到 channel /用户?

android - 什么是通知的 "small icon"mdpi 大小

Android "permanent"应用程序的 super 用户权限?