嘿伙计们我有json数组的问题。在我的代码中,我将手机联系人存储到json数组并将该数组放入对象中。但问题是数组没有完全显示项目,它最后显示点,以便json对象是无效的对象。你可以帮助我跟随我的代码和对象。
for (PhoneContact phoneContact : phoneContacts) {
if (StringUtil.isNotBlank(phoneContact.getContactNumber())) {
phoneContact.setStatus("POSTED");
JSONObject object = new JSONObject();
object.put("contactName", phoneContact.getContactName());
object.put("phoneNumber",
PhoneUtil.getPhoneNumber(phoneContact.getContactNumber()));
JSONObject userobj = new JSONObject();
userobj.put(StringConstant.ID, mapper.getUserId());
// JSONObject groupobj = new JSONObject();
// groupobj.put(StringConstant.ID, groupId);
object.put(StringConstant.USER, userobj);
// object.put("Group", groupobj);
phonenumbers.put(object);
}
}
request.put("contactDetails", phonenumbers);
request.put("isSync", Boolean.FALSE);
} catch (Exception e) {
Log.e(StringConstant.EXCEPTION, e.getMessage());
}
return request;
}
Final JSONObject :
[
{
"phoneNumber": "9822334455",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Sony Ericsson"
},
{
"phoneNumber": "9823145808",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Samsung"
},
{
"phoneNumber": "9822114455",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Inew"
},
{
"phoneNumber": "111",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Vodafone Care"
},
{
"phoneNumber": "141",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Balance Info"
},
{
"phoneNumber": "140",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Recharge"
},
{
"phoneNumber": "121",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Best Deal"
},
{
"phoneNumber": "123",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Top Services"
},
{
"phoneNumber": "*444#",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Bonus Cards"
},
{
"phoneNumber": "198",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Complaints Only"
},
{
"phoneNumber": "*111#",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Self Help"
},
{
"phoneNumber": "8421060095",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Pallavi Mother"
},
{
"phoneNumber": "9713344888",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Pintu"
},
{
"phoneNumber": "8421060094",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Sachin Mate"
},
{
"phoneNumber": "9623461238",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Monu"
},
{
"phoneNumber": "9552516847",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Prashant Korde"
},
{
"phoneNumber": "7385863243",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Asiya"
},
{
"phoneNumber": "2024468994",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Pallavi Home"
},
{
"phoneNumber": "8087419790",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Pallavi"
},
{
"phoneNumber": "9730396745",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Narendra"
},
{
"phoneNumber": "8097528780",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Deepak Kumar"
},
{
"phoneNumber": "9732274869",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Jai"
},
{
"phoneNumber": "555555",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Vid"
},
{
"phoneNumber": "8087419790",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Palavi"
},
{
"phoneNumber": "88203",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Samtsb3"
},
{
"phoneNumber": "8856903080",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Akash"
},
{
"phoneNumber": "9405681761",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Akash Bar"
},
{
"phoneNumber": "8827394156",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Rajju"
},
{
"phoneNumber": "9730313075",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Kaushal"
},
{
"phoneNumber": "9823054740",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Pandey"
},
{
"phoneNumber": "8888888807",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Banti Landge"
},
{
"phoneNumber": "9890589289",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Shirikant"
},
{
"phoneNumber": "9969320485",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Akhiles Sir"
},
{
"phoneNumber": "9049588154",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Bapu"
},
{
"phoneNumber": "9822387529",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Ehwar Varma"
},
{
"phoneNumber": "7588285442",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Vishnu Varma"
},
{
"phoneNumber": "2024489211",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Varma Shop"
},
{
"phoneNumber": "7710002376",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Shoumya"
},
{
"phoneNumber": "9822271444",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Gait Yogesh"
},
{
"phoneNumber": "8087520296",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Grey"
},
{
"phoneNumber": "8796568528",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Deepak"
},
{
"phoneNumber": "8237797002",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Udaram Barsagad"
},
{
"phoneNumber": "8552946297",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Ram Barsagadey"
},
{
"phoneNumber": "8928485985",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Vijay Kumar"
},
{
"phoneNumber": "666666",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Celkon"
},
{
"phoneNumber": "9730332839",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Vinay"
},
{
"phoneNumber": "8044804480",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Medical"
},
{
"phoneNumber": "9370597136",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Shiris Despande"
},
{
"phoneNumber": "9029013326",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Vinay Singh"
},
{
"phoneNumber": "9434824016",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Jai"
},
{
"phoneNumber": "9827023816",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Sushi Tiwari"
},
{
"phoneNumber": "9767718271",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Sachin Iternia"
},
{
"phoneNumber": "9225652817",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Amir LIC"
},
{
"phoneNumber": "9922827717",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Amit Desai"
},
{
"phoneNumber": "9766643946",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Nagesh"
},
{
"phoneNumber": "7709645430",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Vijendra"
},
{
"phoneNumber": "9035897140",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Santosh Nigde"
},
{
"phoneNumber": "7766889900",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Test"
},
{
"phoneNumber": "99439209",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Ravi"
},
{
"phoneNumber": "9405984826",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Bandu Mama"
},
{
"phoneNumber": "8087579957",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Vaishali"
},
{
"phoneNumber": "9096966100",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Pankaj Kamde"
},
{
"phoneNumber": "9970341902",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Pankaj Kamde 2"
},
{
"phoneNumber": "9421721146",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Ashokh Bhau"
},
{
"phoneNumber": "9822245024",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Shailesh"
},
{
"phoneNumber": "7875011018",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Kuldeep"
},
{
"phoneNumber": "9823338047",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Nagendra Bhange"
},
{
"phoneNumber": "9011096507",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Parik"
},
{
"phoneNumber": "9850831764",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Vijay Jadhaw"
},
{
"phoneNumber": "9767511714",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Kamlakar Jadhaw"
},
{
"phoneNumber": "7798205667",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Shebin"
},
{
"phoneNumber": "9623215171",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Iphone Devrlope"
},
{
"phoneNumber": "9039825551",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Jai Mother"
},
{
"phoneNumber": "9545156178",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Prashanth Raghu"
},
{
"phoneNumber": "7506062787",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Vijay Shigh"
},
{
"phoneNumber": "9329844710",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Kartik Bhilai"
},
{
"phoneNumber": "9766255660",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Rahul Electroni"
},
{
"phoneNumber": "2060502090",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Gsit Office"
},
{
"phoneNumber": "7276044889",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Shidhrth Plot"
},
{
"phoneNumber": "9527192044",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Ganesh"
},
{
"phoneNumber": "9730079108",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Shailesh Gokhal"
},
{
"phoneNumber": "9892577898",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "You Broadband"
},
{
"phoneNumber": "2024459381",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Woodland Shop"
},
{
"phoneNumber": "7385502166",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Sachin Mate"
},
{
"phoneNumber": "7057474650",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Kamlakar Jadhaw"
},
{
"phoneNumber": "9584618607",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Jai Mother"
},
{
"phoneNumber": "9335344225",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Rani Didi"
},
{
"phoneNumber": "9313643955",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "+919313643955"
},
{
"phoneNumber": "8806312405",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Vijendra Friend"
},
{
"phoneNumber": "9890654329",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Koonal"
},
{
"phoneNumber": "9263586247",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Ravi"
},
{
"phoneNumber": "9860703945",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07dc5f146d"
},
"contactName": "Rajesh Patil"
},
{
"phoneNumber": "9763674815",
"user": {
"id": "13888ff8-25a3-4d4b-a08a-4d07d...
答案 0 :(得分:0)
FileOutputStream outputStream;
try {
outputStream = openFileOutput("ur.json", Context.MODE_PRIVATE);
outputStream.write("ur file name".getBytes());
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
从/data/data/urapp/files/ur.json读取文件中的json。 如果你想在自己的控制台中看到它,请查看这篇文章string-logcat-will-print