JSONArray jsonArray =
new
JSONArray();
JSONObject jsonObject =
new
JSONObject();
jsonObject.put(
"name"
,
"홍길동"
);
jsonObject.put(
"tel"
,
"12345"
);
jsonArray.put(jsonObject);
jsonObject =
new
JSONObject();
jsonObject.put(
"name"
,
"홍"
);
jsonObject.put(
"tel"
,
"123"
);
jsonArray.put(jsonObject);
new
sendData().execute();
====================================
public
class
sendData
extends
AsyncTask<String, String, Void> {
@Override
protected
Void doInBackground(String... params) {
HttpClient httpClient =
new
DefaultHttpClient();
try
{
HttpEntity httpEntity =
new
StringEntity(jsonArray.toString(),
"UTF-8"
);
httpPost.setEntity(httpEntity);
httpPost.setHeader(
"Content-type"
,
"application/json"
);
try
{
httpClient.execute(httpPost);
}
catch
(ClientProtocolException e) {
e.printStackTrace();
}
catch
(IOException e) {
e.printStackTrace();
}
}
catch
(UnsupportedEncodingException e) {
e.printStackTrace();
}
return
null
;
}
}