键入与JSON迭代器安全警告 [英] Type Safety warning with JSON Iterator
问题描述
我的问题来自于从JSONObject的获得一个Iterator。
My problem comes from getting an Iterator from a JSONObject.
在最简单的形式code发生错误:
Code generating error in its simplest form:
String json = client.retrieveList();
JSONObject jsonList = new JSONObject(json);
Iterator<String> i = jsonList.keys();
while(i.hasNext())
{
String next = i.next();
JSONArray jsonArray = jsonList.getJSONArray(next);
// Do stuff with jsonArray, example: jsonArray.getString(0), jsonArray.getString(1);
}
确切的警告是: 类型安全性:类型迭代器的前pression选中需要转换成符合迭代器
The exact warning is: Type safety: The expression of type Iterator needs unchecked conversion to conform to Iterator
所以,问题是我怎么才能铲除这种警告?
So the question is how can I eradicate this warning?
非常感谢!
推荐答案
在混音code与旧的遗留API-S,你可以得到这样的警告。如果你的真正的要根除你可以用燮pressWarnings标注的警告。这是一个很好的做法,离开晚饭pressed警告旁边的注释。在你的情况,这可能是这样的:
When you mix your code with old legacy API-s you can get this kind of warnings. If you really want to "eradicate" the warning you can use the SuppressWarnings annotation. It is a good practice to leave a comment next to suppressed warning. In your case this may look like:
@SuppressWarnings("unchecked") //Using legacy API
Iterator<String> i = jsonList.keys();
干杯!
这篇关于键入与JSON迭代器安全警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!