我有这种格式的字符串响应:
[{"error":false,"getFriends":{"name":"iman2420","email":"2420@isa.ir","is_online":"1","status":"one comment aboute me","img":"56f3baaad2f111.89286338"}},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":false,"getFriends":{"name":"amin","email":"2421@isa.ir","is_online":"0","status":"all of new statuse","img":"56f424ba2920e4.32579063"}},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true},{"error":true}]
如何在循环中解析这个字符串格式?
答案 0 :(得分:1)
不要指望所有人都是科学家(像我们一样)。
try {
JSONArray json_Array = new JSONArray(response);
for (int i=0;i<json_Array.length();i++) {
JSONObject json_data = json_Array.getJSONObject(i);
boolean getFriendsError = json_data.getBoolean("error");
if (!getFriendsError) {
....
}else{
....
}
}