首页 > 解决方案 > 通过 Symfony API 使用数组发布 JSON 对象

问题描述

我正在尝试将如下 JSON 对象发布到使用 Symfony 开发的后端应用程序(使用 API 平台,前端应用程序和 VueJS):

{
    "weight": "10",
    "category": ["/api/categories/2", "/api/categories/79"]
}

这是我为我的 HTML 表单(在 VueJS 模板中)尝试的内容:

<form action="/api/data" method="post" axiosMethod="post">
   <input type="text" name="weight"> <!-- value=1 -->
   <input type="text" name="category[1]"> <!-- value="/api/categories/2" -->
   <input type="text" name="category[1]"> <!-- value="/api/categories/79" -->
</form>

这是此表单实际发送的 JSON 文件,这不是我想要的:

{
    "weight": "1",
    "category[1]": "/api/categories/79"
}

我也试过这个(这也不起作用,与前一个结果相同):

<form action="/api/data" method="post" axiosMethod="post">
   <input type="text" name="weight"> <!-- value=1 -->
   <input type="text" name="category[]"> <!-- value="/api/categories/2" -->
   <input type="text" name="category[]"> <!-- value="/api/categories/79" -->
</form>

有谁知道我可以将两个类别值放在一个数组中?任何帮助将不胜感激

标签: javascriptjsonformssymfonypost

解决方案


推荐阅读