如何解决有关Java Hashmap的Sonarqube错误

发布于 2025-01-27 07:45:30 字数 432 浏览 2 评论 0原文

我有一个hashmap: 私有静态地图< string,jsonobject> LaserDatalist = new Hashmap< string,jsonobject>(); 我写了代码的这一部分:

public void execute(jsonObject对象){jsonObject reportdata = laserdatalist.get(jsonutil.getAsjSonObject(object,object,loaontologykeys.print_document_id))); } Sonar说此代码有问题: a Map< string,jsonObject>”不能在“字符串”类型中包含“ JSONOBJECT”

如何解决此错误?这个声纳信息是什么意思?

I have a hashMap :
private static Map<String, JSONObject> laserDataList = new HashMap<String, JSONObject>();
I wrote this part of code :

public void execute(JSONObject object) {JSONObject reportData = laserDataList.get(JSONUtil.getAsJSONObject(object, LoanOntologyKeys.PRINT_DOCUMENT_ID)); }
Sonar says this code has problem : A "Map<String, JSONObject>" cannot contain a "JSONObject" in a "String" type

how can I resolve this bug ? what is the meaning of this sonar message ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤云独去闲 2025-02-03 07:45:30

从评论中,我可以看出您不了解问题。

您已经定义了一个地图对象。您已经指定了地图的键是类型字符串,并且值是类型的JSONOBJECT。

当您在地图中查找一个值时,您将“获取”方法传递给密钥类型的值,然后获得值类型的值。在这种情况下,再次,密钥类型为字符串,值类型为JSONOBJECT。您呼叫“ jsonutil.getasjsonobject()”所有返回jsonobject值,而不是字符串。

我不知道您的逻辑在做什么,但也许您需要这个:

JSONObject reportData = laserDataList.get(LoanOntologyKeys.PRINT_DOCUMENT_ID);

I can see from the comments that you're not understanding the problem.

You've defined a Map object. You've specified that the keys of the map are of type String, and the values are of type JSONObject.

When you look up a value in a map, you pass to the "get" method a value of the KEY type, and you get back a value of the VALUE type. In this case, again, the key type is String, and the value type is JSONObject. Your calls to "JSONUtil.getAsJSONObject()" all return JSONObject values, not strings.

I don't know exactly what your logic is doing, but perhaps you need this:

JSONObject reportData = laserDataList.get(LoanOntologyKeys.PRINT_DOCUMENT_ID);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文