public void test() throws IOException {
String jsonString = "[{\"username\":\"xujiaowei\",\"userId\":\"28\"},{\"username\":\"Jason\",\"userId\":\"002\"}}]";
JsonReader jsonReader = new JsonReader(new StringReader(jsonString));
jsonReader.beginArray();
while (jsonReader.hasNext()) {
jsonReader.beginObject();
while (jsonReader.hasNext()) {
String name = jsonReader.nextName();
if (name.equals("username")) {
System.out.println(jsonReader.nextString());
}
if (name.equals("userId")) {
System.out.println(jsonReader.nextInt());
}
}
jsonReader.endObject();
}
jsonReader.endArray();
}
Json数据之Gson解析
最新推荐文章于 2024-09-19 19:39:48 发布