【问题标题】:error in rasa chatbot responce in androidandroid中的rasa聊天机器人响应错误
【发布时间】:2020-11-15 05:48:22
【问题描述】:

我正在使用 rasa 创建聊天机器人,我想将该 rasa 聊天机器人集成到我的 Android 应用程序中。

public void Test(String s) throws JSONException {
        String url = "http://192.168.0.105:5005/webhooks/rest/webhook";
        final String[] myObjAsString = {""};
        JSONObject jsonBody = null;
        try {
            jsonBody = new JSONObject("{\"message\":\""+s+"\",\"sender\":\"Me\"}");
        } catch (JSONException e) {
            e.printStackTrace();
        }

        RequestQueue requestQueue = Volley.newRequestQueue(this);
        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(
                Request.Method.POST, url, jsonBody,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        Log.d("TAG", response.toString());
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                       Log.d("ERROR", error.toString());
                    }
                }
        );
        requestQueue.add(jsonObjectRequest);
    }

以上是我向机器人发送请求的代码。对于测试,我使用的是 rasa 提供的默认训练机器人。 但我收到以下错误。

2020-07-25 19:07:52.418 6615-6615/com.example.bot D/ERROR: com.android.volley.ParseError: org.json.JSONException: Value [{"recipient_id":"Me","text":"Hey! How are you?"}] of type org.json.JSONArray cannot be converted to JSONObject
 

bot 接受响应为 jsonobject 并响应 jsonarray? 如何解决这个问题?

【问题讨论】:

    标签: android json rasa rest


    【解决方案1】:

    看起来 Rasa REST 端点工作正常,但反序列化响应存在问题。回复 here 应该注意这一点。

    使用Request 代替JsonObjectRequest 或使用JsonArrayRequest

    【讨论】:

    • 我检查了您提供的帖子。但我必须发送一些带有 jsonobject 请求的数据,并且在那篇文章中没有发送任何数据
    猜你喜欢
    • 2022-07-25
    • 1970-01-01
    • 2020-11-06
    • 2020-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多