简体   繁体   English

如何配置JSON字段到TypeScript对象属性的映射?

[英]How to configure mapping of JSON fields to TypeScript object properties?

Input JSON: 输入JSON:

{
  "some_field":"some value"
}

Type to be used for mapping: 用于映射的类型:

export inteface SomeType {
  someField:string;
}

How can the mapping between JSON and TypeScript type be configured so that some_field -> someField? 如何配置JSON和TypeScript类型之间的映射,以便some_field - > someField?

You could use decorators to do that . 你可以使用装饰器来做到这一点。 see this post for more details Type Script Decorators 有关详细信息,请参阅此帖子类型脚本装饰器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM