You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Actions SDK应用JSON响应解析失败问题求助

排查Google Actions API v2 JSON解析失败问题

你的问题核心在于返回的响应JSON不符合Actions API v2的规范,模拟器报错的"Cannot find field"是因为你混入了v2不支持的字段,还有部分v1遗留的格式内容。下面是具体的问题分析和修复方案:

问题点拆解

你的响应里包含了多个API v2不认可的冗余或错误字段:

  • speech和displayText:这是v1的顶层字段,v2中这类内容已经通过simpleResponse节点定义,不需要在顶层重复返回。
  • isInSandbox:这个字段是Google发送给你的请求参数,你的响应完全不需要包含它。
  • finalResponse:v2中用expectUserResponse: false来标记对话结束,你当前设置了expectUserResponse: true,这个字段完全多余。
  • customPushMessage:如果你没有使用推送消息功能,不要在响应里加入这个未启用的字段。

修正后的合规响应示例

{
  "conversationToken": "{\"state\":null,\"data\":{}}",
  "expectUserResponse": true,
  "expectedInputs": [
    {
      "inputPrompt": {
        "noInputPrompts": [],
        "richInitialPrompt": {
          "items": [
            {
              "simpleResponse": {
                "textToSpeech": "You're now talking to GActions Integration",
                "displayText": "You're now talking to GActions Integration"
              }
            },
            {
              "basicCard": {
                "buttons": [
                  {
                    "title": "Some Reddit to chill",
                    "openUrlAction": {
                      "url": "https://www.reddit.com"
                    }
                  }
                ],
                "formattedText": "Here's some simp-wave to relax and chill out to",
                "image": {
                  "url": "http://tracks.arte.tv/sites/default/files/styles/jscrop_1007x566/public/c_simpsons_2.jpg?itok=INzKpsvK",
                  "accessibilityText": "A World of Simpsonwave"
                },
                "title": "A World of Simpsonwave",
                "imageDisplayOptions": "CROPPED"
              }
            }
          ],
          "suggestions": []
        }
      },
      "possibleIntents": [
        {
          "intent": "actions.intent.TEXT"
        }
      ]
    }
  ],
  "resetUserStorage": false,
  "userStorage": "{}"
}

额外验证步骤

  1. 确认你的端点返回的HTTP响应头Content-Type是application/json;charset=UTF-8,避免编码导致的解析异常。
  2. 检查JSON语法正确性:确保所有引号、括号匹配,嵌套JSON的转义字符(比如conversationToken里的内容)没有错误。

按照这个格式返回后,模拟器应该就能正确解析你的响应了。

内容的提问来源于stack exchange,提问作者Prashant Warrier

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 06:45:13