Android问题:未将所有获取的手机通讯录号码转换为Json格式

时间:2014-12-24 06:47:39

标签: android

我从Android手机中获取了所有联系人号码但未将所有语音转换为json格式。在一些Android手机,它正在工作,但在我的手机三星Duos,它不工作。它提供了类似的输出

网址现在

{"data":[
 {"phone":"+9187678965433","name":"Home"},
 {"phone":"+9178961042","name":"Vikash(bang)"}, 
 {"phone":"+91826543748","name":"Chandan(mota)"},
 {"phone":"+91867868199","name":"Amit Singh"},
 {"phone":"+9143228811","name":"Jimmi Sinha"},
 {"phone":"+91989769610","name":"Nagar(Aone)"},
 {"phone":"+919465436261","name":"Shahi(Biet)"},
 {"phone":"+917576540555","name":"Pankaj(Biet)"},
"name":"P

请告诉我这是什么问题。

这是我的代码

ContentResolver cr = getContentResolver();
         Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
                null, null, null, null);

         JSONObject jobj ;
         JSONArray arr = new JSONArray();

         if (cur.getCount() > 0) {
            while (cur.moveToNext()) {
                String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
                String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));


                if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
                   // System.out.println("name : " + name + ", ID : " + id);

                    // get the phone number
                    Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,
                                           ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",
                                           new String[]{id}, null);
                    while (pCur.moveToNext()) {
                           phone = pCur.getString(
                                 pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

                           name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));


                           jobj = new JSONObject();
                           try {

                            jobj.put("phone", phone);
                            jobj.put("name", name);

                        } catch (JSONException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }

                           arr.put(jobj);
                          System.out.println("phone" + phone); 
                        // response = callContactList();
                    }
                    pCur.close();
                }
             }


                   jobj = new JSONObject();
            try {
                jobj.put("data", arr);
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            String st = jobj.toString().trim();


            response = callContactList(st);
            } 

谢谢, 阿米特

0 个答案:

没有答案