今天做封装json数据,要封装成这种形式的,如下图:
[java][/java]
JSONArray idCradArray = new JSONArray();
int i = basicInfo.getIdCardPhoto().length;
for (int j = 0; j < i; j++) {
String guidString = basicInfo.getIdCardPhoto(j);
JSONObject stoneObject = new JSONObject();
stoneObject.put("idCardGuid", guidString);
if (guidString == null) {
guidString = "";
}
idCradArray.put(guidString);
}
结果出来的数据是这样的,如下图:
显然这不是我想要的。找了一下资料,只要把JSONObject这2行屏蔽了就行了.代码修改如下:
[java] [/java]
JSONArray idCradArray = new JSONArray();
int i = basicInfo.getIdCardPhoto().length;
for (int j = 0; j < i; j++) {
String guidString = basicInfo.getIdCardPhoto(j);
// JSONObject stoneObject = new JSONObject();
// stoneObject.put("idCardGuid", guidString);
if (guidString == null) {
guidString = "";
}
idCradArray.put(guidString);}
这样,就可以,效果图如下:
如果我想发送下图的json数据该怎么办呢?
应该这样写:
Map<String, String> datas = new HashMap<String, String>();
try {
JSONObject mJsonobjData = new JSONObject();
mJsonobjData.put("isFindMeByCoolCode", "false");
mJsonobjData.put("isFindMeByCarSignNo", "false");
mJsonobjData.put("isFindMeByQq", "false");
mJsonobjData.put("isFindMeByMobile", "false");
mJsonobjData.put("isFindMeByWeixin", "false");
datas.put("memberJson", mJsonobjData.toString());
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
HttpCommandHandler.getInstance().execute(PersonalSettings, datas,
mHandler, ResultBean.class, ctx);
如果我想发送下面这中json数据该怎么办呢?
应该这样写:
JSONArray idCradArray = new JSONArray();
int i = list.size();
for (int j = 0; j < i; j++) {
try {
JSONObject stoneObject = new JSONObject();
stoneObject.put("name", list.get(j).getName());
stoneObject.put("telNo", list.get(j).getNumber());
idCradArray.put(stoneObject);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
Map<String, String> datas = new HashMap<String , String>();
datas.put("paramJson", idCradArray.toString());
HttpCommandHandler.getInstance().execute(MatchTelNoIsFriend,datas, mHandler,MatchTelNoIsFriendBean.class, ctx);