嗨,我正在尝试处理https://firebase.google.com/docs/database/rest/retrieve-data中给出的Firebase Rest服务的响应,以下是我收到的示例响应:
import numpy as np
import matplotlib.pyplot as plt
theta = list(range(1,366))
theta = [i* 2 * np.pi / 365 for i in theta]
radii=np.random.rand(365)
ax = plt.subplot(111, projection='polar')
ax.set_theta_zero_location('N')
ax.set_xticklabels(['Jan', 'Feb', 'Mar', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'])
因此,响应是一个随机键和员工界面:
{
"2": {
"name": "John",
"surname": "Cena"
},
"12": {
"name": "Murphy",
"surname": "R ichard"
},
.
.
.
"8": {
"name": "Alisha",
"surname": "Johnson"
}
}
响应中的元素数量将有所不同。我想在打字稿中处理这个问题。我将其作为对象接收,甚至没有映射数组。 interface Employee{
private name:string;
private surname:string;
}
。请提供解决方法。
答案 0 :(得分:1)
我要说的全部是基于您将要处理的数据
// you can assign the response to employees
const employees: any = res;
// or you can convert this to array;
const data = Object.keys(res).map((key) => {
return { ...res[key], id: key }; <-- here this can be pass to a constructor to return a Employee Object, also you can add a key/id field to the entity.
});
// or many more methods, its all based on how you are going access the data.