有可能在 ArrayList 中不可能放置大内容,然后如果你这样做,它会给你 null?
我正在插入一个带有 32 个 JSONObject 的 JSONArray,每个 JSONObject 都有姓名和电话联系方式。
ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>();
nvp.add(new BasicNameValuePair("something", content));
public void phoneandname(Context c) {
if (cc.isOnline(c) == true) {
db = new Database(c);
Cursor phones = c.getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
null, null, null);
JSONArray jarray = new JSONArray();
db.open();
while (phones.moveToNext()) {
String name = phones
.getString(phones
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String phoneNumber = phones
.getString(phones
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
db.contact_table(name, phoneNumber);
JSONObject json = new JSONObject();
try {
json.put("name", name);
json.put("phone", phoneNumber);
jarray.put(json);
} catch (JSONException e) {
e.printStackTrace();
}
}
upload(jarray, context);
db.close();
Log.i("********", jarray.toString()); IT SHOWS MY ARRAY AND THEN BEFORE UPLOAD IT TO THE SERVER BY POST IT'S NULL...
phones.close();
}
}
public void upload(Object jobject, Context c) {
ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>();
DBupload upload = new DBupload();
DatosRegistro dr = new DatosRegistro(c);
nvp.add(new BasicNameValuePair("content", jobject.toString()));
nvp.add(new BasicNameValuePair("token", dr.hash_final(
dr.token_secret(dr.mail(), "mail"), jobject.toString())));
nvp.add(new BasicNameValuePair("id", String.valueOf(dr
.return_id_phone())));
JSONObject json2 = upload.UploaData(nvp,
"http://anonyme.mariomontes.es/contacts/insert");
try {
if (json2.getInt("error") == 1) {
} else {
db.contact_table(name, phoneNumber);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
谢谢!