json - Angular http.post 嵌套 json

标签 json angular symfony angular5

我正在使用 Angular5 和 Symfony 3.4 以及 FOSUserBundle。

我有类似的东西:

register(username: string, email: string, first: string, second: string)
{
  return this.appHttp.post('register', {username, email, first, second}).subscribe(
    data => {
       this.appHttp.logRequest(data);
    }
  );
}

我需要发送到 API 的是格式化的 json,如下所示:

{
  "email": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f99c94989095b98d9c8a8dd79a9694" rel="noreferrer noopener nofollow">[email protected]</a>",
  "username" : "userTest",
  "plainPassword" : {
    "first" : "123",
    "second": "123"
   }
}

目前,我的 json 看起来像:

{
  "email": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="294c44484045695d4c5a5d074a4644" rel="noreferrer noopener nofollow">[email protected]</a>",
  "username" : "userTest",
  "first": "123",
  "second": "123",
}

如何发布所需的 json ?

谢谢!

最佳答案

只需更改:

{username, email, first, second}

{username, email, plainPassword : {first, second} }

关于json - Angular http.post 嵌套 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48420764/

相关文章:

javascript - Ajax JSON 访问数组,从 JSON 编码服务器响应数组

javascript - 区分 JSON 中的矩阵和列表列表

Symfony2 - 将 Google Analytics 脚本添加到 Twig 中

php - 如何在测试中加载表单类型

json - 输入递归 golang 函数调用

javascript - jQuery ajax 到 PHP,返回错误和空对象

angularjs - Angular2 View Child未定义错误

Angular 2 : Uncaught (in promise): TypeError: Cannot read property 'setParent' of null

angular - 如何更改 Ionic 4 的 ionic 范围引脚字体和格式?

symfony - 在实体存储库中注入(inject)容器