title: how to retrieve the list of contacts in android
body: <p>my purpose to retrieve the list of contacts (name, number) is recorded in a json object, to send via web service to the server</p>
  
  <p>then I found the code to visit contacts, and it is good, I test this code</p>
  
  <pre><code>String id, name;
  
          ContentResolver crs = getContentResolver();
  
          Cursor people = crs.query(ContactsContract.Contacts.CONTENT_URI, null,
                  null, null, null);
  
  
  
          String phone = "";
  
          people.moveToPosition(Contexts.getnbContacts());
  
          while (people.moveToNext())
  
          {
  
              id = people.getString(people
                      .getColumnIndex(ContactsContract.Data._ID));
              name = people.getString(people
                      .getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
  
              if (Integer
                      .parseInt(people.getString(people
                              .getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) &gt; 0) {
  
                  Cursor phones = getContentResolver().query(
                          ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                          null,
                          ContactsContract.CommonDataKinds.Phone.CONTACT_ID
                                  + " = " + id, null, null);
                  while (phones.moveToNext()) {
                      // pdata =
                      // phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DATA));
                      phone = phone
                              + phones.getString(phones
                                      .getColumnIndex(ContactsContract.CommonDataKinds.Phone.DATA))
                              + " and ";
                      ;
                  }
  
                  phones.close();
  
              }
  </code></pre>
  
  <p>My question is: how to save each contact (name, number) in an array or arraylist ...</p>
  
  <p>each table row designated contact</p>
  
  <p>I think the array type is compatible with json format</p>
  
  <p>so how to copy the contacts in a json object</p>