无法使用Api网关在请求正文中传递数组

时间:2018-11-04 08:12:05

标签: json rest api-gateway

我在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"]
}

我正在传递一个称为“部落”的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]"}

我相信错误是由请求正文中的数组引起的

1 个答案:

答案 0 :(得分:0)

我们遇到了同样的问题,我通过将字符串数组更改为以管道分隔的单个字符串并在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)));
        }