【发布时间】:2019-03-07 13:09:07
【问题描述】:
我在 Spring Boot 应用程序上使用 Angular5。我正在尝试以 JSON 格式返回地图。
春天:
//some method
return ResponseEntity.ok((new Gson()).toJson(/*My map object*/));
Angular5:
sql_list = new Map<string,string>();
this.myService.getQueries().subscribe(
data => {
console.log("Received data: ");
console.log(data);
this.sql_list = data;
console.log(this.sql_list.get("query1"));
}
);
在客户端中,我可以看到使用 console.log 接收到的数据很好:
Received data:
{
"query1" : "select * from test",
"query2" : "select * from test2",
"query3" : "select * from test3"
}
但是sql_list 对象在尝试使用map.get(string key) 方法时给了我这个错误:
ERROR TypeError: _this.sql_list.get is not a function
我在那里犯了什么错误?
编辑:遵循弗洛里安的回答,这是有效的:
this.sql_list = new Map<string, string>(Object.entries(data));
【问题讨论】:
标签: json spring typescript angular5