【问题标题】:Cannot pass an array in request body using Api Gateway无法使用 Api Gateway 在请求正文中传递数组
【发布时间】:2019-04-07 21:34:04
【问题描述】:

我在 AWS Api Gateway 中有一个带有 PUT 方法的 API。我在请求正文中传递了一个内容类型为 application/json

的对象
{
  "uuid": "i_1",
  "insiderName": "Sam Keys",
  "profileImage": "https://do6gbw1x8hs3.cloudfront.net/spree/cover_images/53977/default/400.jpg",
  "gender": "Female",
  "fullDescription": "This is the full description",
  "shortDescription": "This is the short description",
  "tribes": ["Adventurer"]
}

我正在传递一个名为tribes 的key 和一个作为数组的值。但我收到了这个错误:

{"message": "Could not parse request body into json: Unexpected character (\'A\' (code 65)): was expecting comma to separate Object entries\n at [Source: [B@5d62dfa1; line: 8, column: 17]"}

我认为错误是由请求正文中的数组引起的

【问题讨论】:

  • 我不知道代码有什么问题,但是为了解决错误,您是否尝试过将数组放入带有键的对象中?

标签: json rest api-gateway


【解决方案1】:

我们遇到了同样的问题,我通过将字符串数组更改为管道分隔的单个字符串并在 API 上解析 Json 后转换回字符串数组来添加解决方法。

        IDictionary<string, string> dictionary = new Dictionary<string, string>();
        foreach (KeyValuePair<string, IEnumerable<string>> reportObject in dictionary)
        {
            // do something with entry.Value or entry.Key
            dictionary[entry.Key] = string.Join("|", reportObject.Value.Where(x => string.IsNullOrWhiteSpace(x)));
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-30
    • 2020-04-16
    • 2021-12-06
    • 2021-07-15
    • 2022-07-15
    • 2022-10-14
    • 1970-01-01
    • 2021-07-23
    相关资源
    最近更新 更多