json - 用该数组的第一个元素替换对象中的每个数组
问题描述
我有一个这样的json:
"Client" : {
"ClientId" : "eertertwetw",
"Username" : "c.client",
"Names" : [
{
"Family" : "ClientFamilyName",
"Given" : [
"ClientGivenName"
]
}
]
}
这个json不是固定的,所以有时候有一些属性,有时候没有。我需要用该数组的第一个元素替换此 Json 中的每个数组。因此,例如,在这种情况下,它就像
"Client" : {
"ClientId" : "eertertwetw",
"Username" : "c.client",
"Names" :
{
"Family" : "ClientFamilyName",
"Given" :
"ClientGivenName"
}
]
}
任何人都可以帮助我找到一种使用 Typescript 的方法吗?
解决方案
let data = { Client: {...} }; // your data
data = data.map(client => {
if (!Object.hasOwnProperty(client.Names, 'Prefix')) {
client.Names.Prefix = null;
}
return client;
});
推荐阅读
- c# - Xamarin 表单中带有圆角skiasharp 矩形的倒计时动画
- android - 我没有在 android Oreo 上收到推送通知,但在较低版本上我收到了
- php - Laravel array_diff() 作为更改日志
- java - LongAdder:try 块怎么会失败?
- javascript - 如何使用 jQuery 验证插件在 keyup 上验证非表单元素中的输入
- c++ - 为什么访问空的 std::optional 时没有 throw 或 sigsegv?
- c# - EventHub ForEach 并行异步
- makefile - 在包含子生成文件之前更新子模块
- c - 无法释放父结构的子结构
- pyomo - 如何使用 pip 安装 Pyomo 的“附加”?