【问题标题】:Powerapps difficulty accessing JSON in collectionPowerapps 难以访问集合中的 JSON
【发布时间】:2018-04-06 00:23:48
【问题描述】:

我无法通过 PowerApps 访问集合中的数据。

我用这个创建集合:

Collect(coll15,mt.GetAnswers("3b....da","application/json",{question:"eco"}))

使用开发者工具 -> 网络选项卡 -> 响应正文 - 返回以下 JSON 数据:

{
"answers": [
{
  "answer": "This is the answer",
  "questions": [
    "Private vehicle eco renewal"
  ],
  "score": 82.901087775826454
}
]
}

集合已创建。

然后我将一个画廊控件添加到我的页面 - 但是我必须绑定到标签的唯一选项是:ThisItem.Value

如果我尝试输入 ThisItem.Value.answer 我收到错误:'.' 的使用无效

如果我输入 ThisItem.answers.answer 我会收到错误:名称无效

这是招摇文件:

{
"swagger": "2.0",
"info": {
  "version": "1.0.0",
  "title": "mt",
  "description": "mt"
},
"host": "westus.api.cognitive.microsoft.com:443",
"basePath": "/",
"schemes": [
  "https"
],
"consumes": [],
"produces": [
  "application/json"
],
"paths": {
  "/qnamaker/v2.0/knowledgebases/eeeee.....eeeee/generateAnswer": {
     "post": {
        "summary": "GetAnswers",
        "description": "Get answers from qna",
        "operationId": "GetAnswers",
        "parameters": [
           {
              "name": "body",
              "in": "body",
              "schema": {
                 "type": "object",
                 "properties": {
                    "question": {
                       "type": "string",
                       "description": "question",
                       "x-ms-summary": "question",
                       "title": "question",
                       "x-ms-visibility": ""
                    }
                 },
                 "default": {
                    "question": "hi"
                 },
                 "required": [
                    "question"
                 ]
              },
              "required": true
           }
        ],
        "responses": {
           "default": {
              "description": "default",
              "schema": {
                 "type": "string"
              }
           }
        }
     }
  }
},
"definitions": {},
"parameters": {},
"responses": {},
"securityDefinitions": {
  "api_key": {
     "type": "apiKey",
     "in": "header",
     "name": "Ocp-Apim-Subscription-Key"
  }
},
"security": [
  {
     "oauth2_auth": [
        "Offline-Access"
     ]
  }
],
"tags": []
}

我有什么方法可以访问集合中的答案文本吗?

感谢您的帮助,

标记

【问题讨论】:

  • 什么是mt?您创建的自定义连接器还是现有的?如果是自定义连接器,能否分享一下它的 OpenAPI/Swagger 定义?
  • 嗨 - 是的,它是一个自定义连接器。我在web.powerapps.com 中创建了它 - 我看不到如何下载 swagger 文件。能不能给点建议?
  • 如果您访问 web.powerapps.com,然后选择数据 --> 自定义连接器,您应该会看到您拥有的连接器列表,然后从那里下载 swagger。有关详细信息,请参阅imgur.com/a/RS93P。请记住,如果您共享 swagger 文件,请删除您不想共享的所有密钥/密码/信息。操作/对象定义可能是您遇到问题的地方。
  • 谢谢卡洛斯 - 我已将 swagger 文件添加到我的问题中 - 我不确定我需要更改什么(如果有的话)。

标签: swagger powerapps


【解决方案1】:

问题是连接器定义中操作的响应类型是字符串:

    "responses": {
       "default": {
          "description": "default",
          "schema": {
             "type": "string"
          }
       }
    }

但是您的响应是一个对象。如果您更新自定义连接器以改用类型化对象,您应该能够访问操作的响应。类似于以下架构的内容:

    "responses": {
      "default": {
        "description": "default",
        "schema": {
          "type": "object",
          "properties": {
            "answers": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "answer": {
                    "type": "string"
                  },
                  "questions": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "score": {
                    "type": "number",
                    "format": "float"
                  }
                }
              }
            }
          }
        }
      }
    },

请注意,在门户 (web.powerapps.com) 中,如果您转到自定义连接器定义,然后选择“编辑”,则可以转到操作,然后选择要编辑的响应:

然后使用“从样本导入”选项

这样,如果您输入来自 API 的响应示例,它将为您创建架构(类似于我上面的架构)。

【讨论】:

    猜你喜欢
    • 2020-10-08
    • 1970-01-01
    • 2021-01-04
    • 2020-09-27
    • 2020-02-16
    • 2022-01-27
    • 2013-03-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多