上传类似{"device_id":"8bae9c73330c3cee","user_id":"141","ios_lang_key":"en","person":[{"email":"201677577@qq.com","first_name":"nick","last_name":"nick","phone":"1"},
List<Person> list = new ArrayList<Person>();
Person p = new Person("201677577@qq.com","forrey","forrey","1");
JSONObject js = new JSONObject();
list.add(p);
p = new Person("201677577@qq.com","nick","nick","2");
list.add(p);
p = new Person("201677577@qq.com","forrey","forrey","3");
list.add(p);
Gson gs = new Gson();
JSONObject object=new JSONObject();
JSONArray jsonArray=new JSONArray();
try {
for(int i = 0; i < list.size() - 1 ; i ++ )
{
js.put("email",list.get(i).getEmail());
js.put("first_name",list.get(i).getFirst_name());
js.put("last_name",list.get(i).getLast_name());
js.put("phone",list.get(i).getPhone());
jsonArray.put(js);
}
object.put("person", jsonArray);
} catch (JSONException e) {
e.printStackTrace();
}
}
{"email":"201677577@qq.com","first_name":"forrey","last_name":"forrey","phone":"1"},{"email":"201677577@qq.com","first_name":"forrey","last_name":"forrey","phone":"1"}]}的报文
private void tojson() {
List<Person> list = new ArrayList<Person>();
Person p = new Person("201677577@qq.com","forrey","forrey","1");
JSONObject js = new JSONObject();
list.add(p);
p = new Person("201677577@qq.com","nick","nick","2");
list.add(p);
p = new Person("201677577@qq.com","forrey","forrey","3");
list.add(p);
Gson gs = new Gson();
JSONObject object=new JSONObject();
JSONArray jsonArray=new JSONArray();
try {
for(int i = 0; i < list.size() - 1 ; i ++ )
{
js.put("email",list.get(i).getEmail());
js.put("first_name",list.get(i).getFirst_name());
js.put("last_name",list.get(i).getLast_name());
js.put("phone",list.get(i).getPhone());
jsonArray.put(js);
}
object.put("person", jsonArray);
} catch (JSONException e) {
e.printStackTrace();
}
}