My problem comes from getting an Iterator from a JSONObject.

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);
}

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?

Many thanks!

推荐答案

我知道这是个陈词滥调,但对于future 的搜索者来说.

you can also infer a generic and cast the returns of the iterator methods...

Iterator<?> i = jsonList.keys();

while(i.hasNext())
{
    String next = (String) i.next();
    ...

Json相关问答推荐

使用Powershell脚本将配置信息块添加到json文件

将json数组反序列化为选项 struct

如何使用Aeson解码带有Unicode字符的JSON文件?

处理输入数据并转换为更简单的格式-PowerBI

在AWS步骤函数中将字符串解析为JSON&S映射状态

递归解码嵌套列表(具有任意深度的列表列表)

删除 JOLT 中的方括号

从包含 JSON 对象序列的文件中获取第一个 JSON 对象

使用Powershell将JSON文件加载到SQL Server表格

在 NX 工作区中跨多个应用共享 ngx-translate 翻译文件

使用 map_values Select 包含空格的字符串未按预期工作

从 oracle 数据库中的 json blob 打印值

将文本转换为 python 列表

使用 jq Select 键:值并输出为数组

jquery用json数据填充下拉列表

将 JSON 对象推送到 localStorage 中的数组

Swift :将 struct 转换为 JSON?

JSON 模式 - 如果对象*不*包含特定属性则有效

强制 JSON.NET 在序列化 DateTime 时包含毫秒(即使 ms 组件为零)

使用新的 Net Core 3.0 Json 时忽略属性