线程“主” org.json.JSONException中的异常:找不到JSONArray [0]

时间:2019-07-10 13:55:28

标签: java json

尝试运行时出现以下错误,但我无法弄清楚问题出在哪里:

Exception in thread "main" org.json.JSONException: JSONArray[0] not found error 

代码是:

String urlAddress = webAddress + address.getStreetNumber() + "+" + address.getStreetName() + "+" +
    address.getStreetType() + "+" + address.getCityName() + "+" + address.getProvince() + c +
    key;

URL url = new URL(urlAddress);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
BufferedReader get = new BufferedReader(new InputStreamReader(connection.getInputStream()));
System.out.println(urlAddress);

StringBuffer jsonString = new StringBuffer();
while ((writeLine = get.readLine()) != null) {
    jsonString.append(writeLine);
}

String name = person.getFirstName() + " " + person.getLastName() + person.getSpouseFirstName() + " " +
    person.getSpouseLastName();

String name2 = person.getFirstName() + " " + person.getLastName();

JSONObject jsonObj = new JSONObject(jsonString.toString());
JSONArray getAnother = jsonObj.getJSONArray("results");
JSONObject outCome = getAnother.getJSONObject(0);
JSONObject geo = outCome.getJSONObject("geometry");

0 个答案:

没有答案