0

i'm new to android development!

I'm trying to pass string in json object

Code:

 String URL="http://some ip address"; //Here i have to call clientInfo

 protected JSONObject doInBackground(String... args) {


        String no_of_fishes = args[3];
        String no_of_alarms = args[2];
        String password = args[1];
        String username= args[0];

        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("username", username));
        params.add(new BasicNameValuePair("password", password));
        params.add(new BasicNameValuePair("no_of_alarms", no_of_alarms));
        params.add(new BasicNameValuePair("no_of_fishes", no_of_fishes));

        JSONObject json = jsonParser.makeHttpRequest(URL, "POST", params);

        return json;

    }


public static ArrayList<String> getClientList() {
    ArrayList<String> clientList = new ArrayList<>();
    BufferedReader br = null;
    try {
        br = new BufferedReader(new FileReader("/proc/net/arp"));
        String line;
        while ((line = br.readLine()) != null) {
            String[] clientInfo = line.split(" +");
            String mac = clientInfo[3];
            if (mac.matches("..:..:..:..:..:..")) {
                clientList.add(clientInfo[0]);
                ipadd.setText("Client Ip:" + clientInfo[0]);
            }
        }
    } catch (java.io.IOException aE) {
        aE.printStackTrace();
        return null;
    }
    return clientList;
}

How do i call clinentInfo in String URL,i'm new to java and android please any one help how to do this.

kiran reddy
  • 31
  • 1
  • 6

2 Answers2

0

You can put the clientInfo array to JSON by using the below code

JSONObject jsonobj= new JSONObject();//create json object
jsonobj.put("name", new JSONArray(clientInfo[]));
Gayathri Rajan
  • 369
  • 1
  • 6
  • 18
0

If i understand correctly, this is what you want

JSONArray clients= new JSONArray(getClientList());
JSONObject res = new JSONObject();
res.put("clientlist",clients);
Aditya K
  • 466
  • 4
  • 8