public class PhoneInfo {
private String name;
private String phone;
public PhoneInfo(String name, String phone) {
this.name = name;
this.phone = phone;
}
public String getName() {
return name;
}
public String getPhone() {
return phone;
}
}
private String name;
private String phone;
public PhoneInfo(String name, String phone) {
this.name = name;
this.phone = phone;
}
public String getName() {
return name;
}
public String getPhone() {
return phone;
}
}
/**生成K--V
* @param list */
public void GetKV(List<PhoneInfo> list){
* @param list */
public void GetKV(List<PhoneInfo> list){
//生成的格式[{"number":"010-89193313","name":"直聘招聘助手"},{"number":"02886544200","name":"来电专线"}]
//list转对象
PhoneInfo[] phoneInfoArry={};
phoneInfoArry = list.toArray(phoneInfoArry);
//list转对象
PhoneInfo[] phoneInfoArry={};
phoneInfoArry = list.toArray(phoneInfoArry);
System.out.println(JSON.toJSON(phoneInfoArry).toString()+"---------------");
}
}
特别注意一点。实体类直接生成最好.如果该大写的,小写了,这里就无法生成!!!
public StringEntity LoadData() {//这样也可以生成 JSONObject method = null; try { JSONObject param = null; method = new JSONObject(); param = new JSONObject(); param.put("ver", "6.1.0".replace("v", "")); param.put("os", "2"); param.put("userId", BBSUtil.getUserid(getActivity())); Log.e("未加密>>>>>", param.toString()); Log.e("已加密>>>>>", AESNoKey.encrypt(param.toString())); // method.put("param",AESNoKey.encrypt(param.toString())); Log.e("最终>>>", method.toString()); try { return new StringEntity(param.toString(), "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } catch (JSONException e) { e.printStackTrace(); } return null; }