我正在开发一个基于 web 服务的 android 应用程序。我有一个问题如何发送创建以下结构并发布到网络服务。遵循结构。
{
"petData": {
"pet_name_string(petname_gender_size)": [
{
"pro_id1": "idoftheprocedure",
"pro_price1": "priceoftheprocedure"
},
{
"pro_id2": "idoftheprocedure",
"pro_price2": "priceoftheprocedure"
},
{
"pro_id..n": "idoftheprocedure",
"pro_price..n": "priceoftheprocedure"
}
]
}
}
尝试使用以下代码。
String url = Constents.register_vet_url;
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("content-type", "application/json");
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, 25000);
HttpConnectionParams.setSoTimeout(httpParams, 25000);
HttpClient httpClient = new DefaultHttpClient(httpParams);
JSONObject jsonObject = new JSONObject();
jsonObject.put(Constents.vet_name, Constents.vetName);
jsonObject.put(Constents.vet_address, Constents.vetAddress);
jsonObject.put(Constents.vet_email,Constents.vetEmailAdress);
jsonObject.put(Constents.vet_phone,Constents.vetPhoneNumber);
jsonObject.put(Constents.vet_password,Constents.vetPassword);
jsonObject.put(Constents.vet_emergency_service,Constents.vetEmailAdress);
jsonObject.put(Constents.is_represented, String.valueOf(isRepresentedPet));
JSONArray jsonArray = new JSONArray();
JSONObject obj = new JSONObject();
obj.put(Constents.vet_booking_email, Constents.vetEmailAdress);
obj.put(Constents.vet_short_summary, Constents.vetShortSummery);
jsonArray.put(obj);
jsonObject.put(Constents.rep_data, jsonArray);
所以请建议我如何在网络服务中发送 pet_data。谢谢