类型不匹配:无法从 org.json.JSONObject 转换为 org.json.simple.JSONObject
Type mismatch: cannot convert from org.json.JSONObject to org.json.simple.JSONObject
执行以下代码时出现类型不匹配错误。请帮我解决一下。
/**
* Gets the versionID for the project.
*
* @param versionName
* @param projectId
* @throws IOException
* @return the ID for the specified Version in the specified Project
*/
public static String getVersionID(final String versionName, final String projectId)
throws IOException {
// Get list of versions on the specified project
final JSONObject projectJsonObj =
httpGetJSONObject(ZAPI_URL + "util/versionBoard-list?projectId=" + projectId);
if (null == projectJsonObj) {
throw new IllegalStateException("JSONObject is null for projectId=" + projectId);
}
final JSONArray versionOptions = (JSONArray) projectJsonObj.get("versionOptions");
// Iterate over versions
for (int i = 0; i < versionOptions.length(); i++) {
final JSONObject obj2 = versionOptions.getJSONObject(i);
// If label matches specified version name
if (obj2.getString("label").equals(versionName)) {
// Return the ID for this version
return obj2.get("value");
// return obj2.getString("value");
}
}
throw new IllegalStateException("Version ID not found for versionName=" + versionName);
}
错误在以下行:
final JSONObject obj2 = versionOptions.getJSONObject(i);
然后是 if
部分和 return
部分。
确保您导入的是 org.json.JSONObject
,而不是 org.json.simple.JSONObject
。该错误表明您的代码正在尝试转换为后者,但收到的是前者。因为两个类本地名称相同,很容易不小心导入错
执行以下代码时出现类型不匹配错误。请帮我解决一下。
/**
* Gets the versionID for the project.
*
* @param versionName
* @param projectId
* @throws IOException
* @return the ID for the specified Version in the specified Project
*/
public static String getVersionID(final String versionName, final String projectId)
throws IOException {
// Get list of versions on the specified project
final JSONObject projectJsonObj =
httpGetJSONObject(ZAPI_URL + "util/versionBoard-list?projectId=" + projectId);
if (null == projectJsonObj) {
throw new IllegalStateException("JSONObject is null for projectId=" + projectId);
}
final JSONArray versionOptions = (JSONArray) projectJsonObj.get("versionOptions");
// Iterate over versions
for (int i = 0; i < versionOptions.length(); i++) {
final JSONObject obj2 = versionOptions.getJSONObject(i);
// If label matches specified version name
if (obj2.getString("label").equals(versionName)) {
// Return the ID for this version
return obj2.get("value");
// return obj2.getString("value");
}
}
throw new IllegalStateException("Version ID not found for versionName=" + versionName);
}
错误在以下行:
final JSONObject obj2 = versionOptions.getJSONObject(i);
然后是 if
部分和 return
部分。
确保您导入的是 org.json.JSONObject
,而不是 org.json.simple.JSONObject
。该错误表明您的代码正在尝试转换为后者,但收到的是前者。因为两个类本地名称相同,很容易不小心导入错