有可能在ArrayList中不可能放大內容,然後如果你這樣做會給你null?JSONArray null content Java&Android
我插入一個帶有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();
}
}
謝謝!
你也可以編輯實際的問題是什麼?代碼看起來不錯:) – yoshi 2012-07-14 17:48:03