我发现一个github有一个开源项目,但它已经坏了。它试图从https://api.randomuser.me/?nat=gb
中获取JSON我在线程" main"中得到错误Exception。 java.lang.IllegalStateException:不是JSON对象:null
当我尝试将其更改为数组时,我得到的错误是它不是任何数组。是什么给了什么?
String json = readUrl(RANDGEN_URL);
JsonParser jsonParser = new JsonParser();
JsonObject firstNameObject = jsonParser.parse(json)
.getAsJsonObject().getAsJsonArray("results").get(0)
.getAsJsonObject().getAsJsonObject("name");
String firstNameString = firstNameObject.get("first").getAsString();
JsonObject lastNameObject = jsonParser.parse(json)
.getAsJsonObject().getAsJsonArray("results").get(0)
.getAsJsonObject().getAsJsonObject("name");
String lastNameString = lastNameObject.get("last").getAsString();
Random randMail = new Random();
int setMail = randMail.nextInt(90) + 10;
String mail = firstNameString + "." + lastNameString + "" + setMail + "@gmail.com";
JsonObject usernames = jsonParser.parse(json)
.getAsJsonObject().getAsJsonArray("results").get(0)
.getAsJsonObject().getAsJsonObject("login");
String user = usernames.get("username").getAsString();
if (user.length() > 12) {
Random randNum = new Random();
int setNum = randNum.nextInt(90) + 10;
user = user.substring(0, Math.min(user.length(), 10)) + setNum;
}
答案 0 :(得分:-2)
你使用什么图书馆?
<h1><img src="http://www.chinabuddhismencyclopedia.com/en/images/thumb/b/b8/Nature.jpg/240px-Nature.jpg"/></h1>
<img id="thisOne" src="http://www.chinabuddhismencyclopedia.com/en/images/thumb/b/b8/Nature.jpg/240px-Nature.jpg"/>