0

我是 JavaScript 和 Dynamics CRM 的新手。我有以下代码:

var analysisCode = Xrm.Page.getAttribute("rf_analysiscode").getValue()[0].entityValues;

作为 的值analysisCode,我得到以下输出:

{
    "rf_name":{"name":"rf_name","value":"ABC"},
    "rf_code":{"name":"rf_code","value":"ABC"},
    "createdon":{"name":"createdon","value":"24.1.2022 10.39"}
}

但我只想得到 rf_code。我该如何找回它?

4

2 回答 2

0

像这样将结果解析为 JSON:

const analysisCodeObj = JSON.parse(analysisCode);

得到rf_code这样的:

const rfCodeObj = analysisCodeObj["rf_code"];
于 2022-03-01T16:08:33.063 回答
-1

尝试这个:

analysisCode = {
    "rf_name":{"name":"rf_name","value":"ABC"},
    "rf_code":{"name":"rf_code","value":"ABC"},
    "createdon":{"name":"createdon","value":"24.1.2022 10.39"}
};
let rf_code = analysisCode.rf_code;
console.log('rf_code : ', rf_code);
console.log('rf_code Value : ', rf_code.value);

如果您以字符串形式获取输出,首先需要解析输出,然后您可以从该 json 中获取任何值。

尝试这个:

analysisCode = '{"rf_name":{"name":"rf_name","value":"ABC"},"rf_code":{"name":"rf_code","value":"ABC"},"createdon":{"name":"createdon","value":"24.1.2022 10.39"}}'
let rf_code = JSON.parse(analysisCode).rf_code;
console.log('rf_code : ', rf_code);
console.log('rf_code Value : ', rf_code.value);

于 2022-03-01T16:44:14.497 回答