gpt4 book ai didi

json - 使用 angular2 从 JSON 中获取键和值

转载 作者:太空狗 更新时间:2023-10-29 18:21:30 25 4
gpt4 key购买 nike

我正在寻找如何在我的 angular2 应用程序中使用 JSON 的最佳解决方案。

我的 JSON 是:

{
"rightUpperLogoId": {
"id": 100000,
"value": ""
},
"navbarBackgroundColorIdCss": {
"id": 100001,
"value": ""
},
"backgroundColorIdCss": {
"id": 100002,
"value": ""
},
"translationIdFrom": {
"value": "90000"
},
"translationIdTo": {
"value": "90055"
}
}

这个 JSON 类似于应用程序 UI 的配置文件。在我的应用程序中,我想从 rightUpperLogoId 获取 id,它是 100000。有了这个 id,我需要在我的后端 REST api 上执行 GET 任务,并将返回值设置为 value。谢谢

最佳答案

您可以利用 Rx 运算符,例如 flatMapObservable.forkJoin/Observable.of

这是一个示例:

this.http.get('config.json')
.map(res => res.json())
.flatMap(config => {
return Observable.forkJoin(
Observable.of(config),
// For example for the request. You can build the
// request like you want
this.http.get(
`http://.../${config.rightUpperLogoId.id}`)
);
})
.map(res => {
let config = res[0];
let rightUpperLogoIdValue = res[1].json();

config.rightUpperLogoId.value = rightUpperLogoIdValue;

return config;
})
.subcribe(config => {
// handle the config object
});

本文可以为您提供更多提示(“聚合数据”部分):

关于json - 使用 angular2 从 JSON 中获取键和值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37408062/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com