【发布时间】:2020-02-14 15:22:25
【问题描述】:
我有这个代码:
try {
URL url = new URL("My api url");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.addRequestProperty("User-Agent", "MyUserAgent");
InputStream inputStream = connection.getInputStream();
InputStreamReader reader = new InputStreamReader(inputStream);
JsonElement element = new JsonParser().parse(reader);
System.out.println(element);
} catch (IOException e) {
e.printStackTrace();
}
我的 api 响应:
[
{
"id": 12345,
"name": "1.0"
}
]
我需要将name参数作为字符串获取,但我不知道该怎么做。
【问题讨论】:
-
名称是字符串否?
"1.0" -
@YCF_L 是的。
-
好的,你说的我需要将name参数作为字符串获取,但是我不知道该怎么做
-
我想做一个返回name参数的方法。
标签: java arrays json arraylist gson