如何从Angular Typescript向Web Api发送复杂的嵌套JSON? [英] How to send complex nested JSON from Angular Typescript to Web Api?
问题描述
我的json数据有2个问题因为我用来发送它平
示例typescript类模型
UserID: number;
AppID: number;
Key: string;
HearingsAndEventsType: number
过去我会像这样发送。
{
"UserID": 61525,
"AppID": 15,
"Key": "abc",
"HearingsAndEventsType": 1
}
不是任何情况,我必须作为嵌套对象发送,对JSON对象进行2次更改
NOT ANYMORE, I have to send as the nested object with 2 changes to the JSON object
- PageQueryString:{...
- },
HearingsAndEventsType:1
这是我需要的强制性结构send会看起来像这样INSTEAD
{
"PageQueryString": {
"UserID": 61525,
"AppID": 15,
"Key": "abc"
},
"HearingsAndEventsType": 1
}
我试着在下面的链接中提出这个问题,但我认为它的篇幅太长,让人们无法理解我的内容需要。因此,其他问题几乎是相同的事情......所以对于善良和善于帮助的人来说,2个问题的价格为1。 thx
I tried to ask the question in the link below, but I THINK it was too long in length for people to understand what I was needing. Thus other question is pretty much the same thing.... so to the person kind and smart enough to help, 2 questions for the price of 1 . thx
当模型平坦时,Angular Typescript将复杂的json数据发送到web api
Essential i使用JSON stringify并尝试发送模型,但我需要其他json
Essential i use JSON stringify and try and send model over, but I need to other the json
getPageCommonData(menu: Menu) {
return this.http.post(pageCommonData, JSON.stringify(menu), httpOptions)
....
}
推荐答案
您只需要创建两个模型:
You just need to create two models:
class QueryString {
UserID: number;
AppID: number;
Key: string;
}
class Menu {
PageQueryString: QueryString;
HearingsAndEventsType: number;
}
这篇关于如何从Angular Typescript向Web Api发送复杂的嵌套JSON?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!