angular - 嵌套值对象为空
问题描述
我有一个发送到我的 Web Api 的对象,一旦它到达我的 WebAPI,嵌套对象为空(问题在于 gatewayRoles)
服务.ts
processRequest(request: IRequest) {
var result;
var objectToSend = JSON.stringify(request);
var headers = new Headers();
headers.append('Content-Type', 'application/json');
console.log('object to send ' + objectToSend);
return this._http.post(environment.BASE_API_URL + "XXXX", objectToSend, {
headers: headers
})
.map((res: Response) => res.json())
}
我要求
import { IGatewayRole } from './gateway-role';
export interface IRequest {
req_id: number;
req_type_id: number;
gatewayRole: IGatewayRole[];
}
网关角色
export interface IGatewayRole {
id: number;
name: string;
}
JSON
{
"req_id": 0,
"req_type_id": 1,
"gatewayRole": {
"id": XXXXX,
"name": "XXXXXXX"
}
}
webAPI(数据正确进入webapi,只有网关角色未映射,值为空
public class Request {
public int req_id {
get;
set;
}
public int req_type_id {
get;
set;
}
public List < IGatewayRole > gatewayRole = new List < IGatewayRole > ();
}
public class IGatewayRole {
public int id {
get;
set;
}
public string name {
get;
set;
}
}
[HttpPost]
[Route("API/XXXXXX/")]
[AcceptVerbs()]
public HttpResponseMessage ProcessRequest(Request val) {
try {
sp_processRequestResult result = null; //
return Request.CreateResponse(HttpStatusCode.OK, _modelFactory.Create(result));
} catch (Exception ex) {
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
}
}
解决方案
推荐阅读
- bash - 计算bash中带有许多小数的2个数字之间的百分比增加/减少
- java - 内部类泛型 - 不兼容的类型
- javascript - 在网页上捕获签名(通过平板电脑屏幕)
- swift - Xcode NSEException,信号 SIGABRT 无法弄清楚
- jquery - JQuery - 语法
- django - Wagtail 前端的文档链接
- java - 对循环中更改的最终变量的引用
- typescript - 使用 TypeScript 进行部分应用
- vb.net - 如何增加 DataGridView 的列标题工具提示的显示时间?
- javascript - 使用 v-html 时无法读取 null 的属性“_pending”和