package Servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import Archivos.RegresarUsuarios;
import Archivos.Usuario1;
import java.util.ArrayList;
import org.json.simple.*;

public class RegresarUsuariosServlet extends HttpServlet {

    private static final long serialVersionUID = 1L;

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        response.setContentType("text/html");
        PrintWriter out = response.getWriter();

        String e = request.getParameter("username");
        
        ArrayList<Usuario1> u = RegresarUsuarios.validate(e);
        if (u!=null) {
            String format = request.getParameter("format");
            if (format.equals("json")) {
   JSONObject json = new JSONObject();
   json.put("success", true);
   
   JSONArray users = new JSONArray();
   for (int i = 0; i < u.size(); i++) {
   	JSONObject user = new JSONObject();
       user.put("idUsuario", u.get(i).getidUsuario());
       user.put("usuario", u.get(i).getidUsuario());
       user.put("password", u.get(i).getPassword());
       user.put("nickname",u.get(i).getNickname());
       user.put("email", u.get(i).getEmail());
       user.put("status",u.get(i).getStatus());
       users.add(user);
   }

   json.put("users", users);
   out.print(json);
}
        } else {
            String format = request.getParameter("format");
            if (format.equals("json")) {
                JSONObject json = new JSONObject();
                json.put("success", false);
                json.put("message","ERROR");
                out.print(json);
               
                
            }

        }

        out.close();
    }
}

@@ -975,32 +975,45 @@
 eter(%22format%22);%0A
+            %0A
             if (
@@ -1037,16 +1037,29 @@
 on%22)) %7B%0A
+             
    JSONO
@@ -1089,16 +1089,29 @@
 ject();%0A
+             
    json.
@@ -1139,27 +1139,57 @@
 %0A   
-%0A   JSONArray
+             %0A                    JSONObject
  user
-s
  = n
@@ -1199,17 +1199,31 @@
 JSON
-Array();%0A
+Object();%0A             
    f
@@ -1265,45 +1265,18 @@
 %0A   
-%09JSONObject user = new JSONObject();%0A
+          
     
@@ -1318,32 +1318,45 @@
 etidUsuario());%0A
+             
        user.put(
@@ -1388,24 +1388,37 @@
 Usuario());%0A
+             
        user.
@@ -1454,24 +1454,37 @@
 assword());%0A
+             
        user.
@@ -1519,24 +1519,37 @@
 ickname());%0A
+             
        user.
@@ -1579,24 +1579,37 @@
 etEmail());%0A
+             
        user.
@@ -1655,34 +1655,21 @@
     
-users.add(user);%0A   %7D%0A%0A
+        
    
+  
 json
@@ -1682,40 +1682,119 @@
 user
-s
 %22, user
-s
 );%0A   
-out.print(json);%0A
+                 out.print(user);%0A                %7D             %0A                    %0A            
 %7D%0A  

Revert "CorreccionJSON"