-2

this.getdata() 为我提供以下格式的数据。

{ 
   "MyRequest":{ 
      "Month":"",
      "Number":"003254810"
   }
}

我有另一个请求,我想将上面的 json 属性传递给 Myrequest。我怎样才能达到那部分?有人可以帮助我吗?

{
 "sol1" : 123,
 "MyRequest" : {

        }

}
4

2 回答 2

1

使用[]添加property如下。

var a = { 
   "MyRequest":{ 
      "Month":"",
      "Number":"003254810"
   }
};
var b = {};
b['sol1'] = 123;
b['MyRequest'] = a.MyRequest;
console.log(b);

于 2019-10-23T09:03:30.233 回答
0

interface你可以为你的请求的形状声明一个。

    export interface SecondRequest {
         solo: string;
         MyRequest: {
           Month: string;
           number: string;
         };
    }

然后,只需分配MyRequest给您的SecondRequst对象。

secondRequest: SecondRequest = <SecondRequest>{};
...
this.secondRequest.MyRequest = MyRequest;
于 2019-10-23T09:10:47.793 回答