对于某些应返回JSONObject的方法的调用,我正在接收ClassCastException。我了解该方法将返回JSONArray,但是
1:我不知道为什么(getZillowZpidByAddress返回JSONObject)
2:我不知道如何操纵代码来检索JSONArray并从中提取JSONObject。
调用api:
JSONObject j = zillow.getZillowZpidByAddress(zwsid, "9048 S. DOBSON AVENUE",
"Chicago, IL 60619");
使用以下API的步骤:
public JSONObject getZillowZpidByAddress(final String zwsId, final String address, final String cityStateZip)
{
final String parameterQuery = buildGetDeepSearchResultsParameterQuery(zwsId, address, cityStateZip, false);
JSONObject jsonResponse = getZillowJsonResponse(properties.deepSearchResultsUrl(), parameterQuery);
//exception on this line
return getJsonNthChildObject(jsonResponse
, new String[]{
"SearchResults:searchresults"
, "response"
, "results"
, "result"}
, "zpid");
}
错误:
java.lang.ClassCastException: org.json.JSONArray cannot be cast to org.json.JSONObject
将j铸造到JSONArray将不允许调用该方法,并且在调试中评估表达式会抛出相同的异常。
我正在通过它运行数百个地址,并且JSONObject被存储到j中的8/10次,但是我不知道在返回JSONArray的情况下该怎么做。我不知道如何在不调用此方法的情况下查看数组并探出对象。