[英]convert TypeScript object to JSON
I want to convert a typescipt object to JSON我想将 typecipt object 转换为 JSON
ObjectToConvert = { key : value }
public getJson(key: string, value: string) {
//I passed this values when I called the method : key="attr",value="on"
console.log(JSON.stringify({ ObjectToConvert }))
// The result is {"key":"on"} instead of {"attr":"on"}
I want to know why the result is not what I passed as parameter.我想知道为什么结果不是我作为参数传递的。
Use computed property names :使用计算属性名称:
ObjectToConvert = { [key] : value }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.