Type 1:
通过 JsonArray 和 JsonObject 解析
String str= String.format("[{"id":"5","version":"5.5","name":"Name1"}," +
"{"id":"6","version":"6.6","name":"Name2"}]");
try {
JSONArray jsonArray=new JSONArray(str);
for (int i=0;i<jsonArray.length();i++){
JSONObject obj=jsonArray.getJSONObject(i);
Log.e(TAG, "onCreate: "+obj.getString("id"));
Log.e(TAG, "onCreate: "+obj.getString("version"));
Log.e(TAG, "onCreate: "+obj.getString("name"));
}
} catch (JSONException e) {
e.printStackTrace();
}
Type2:
compile 'com.google.code.gson:gson:2.7'
Gson gson = new Gson();
listNew = gson.fromJson(result, new TypeToken<List<RankData>>() {}.getType());