[英]How to parse array inside json object in android java?
[英]How to post json array inside json object in Android
我想將數據發送到Web服務。 但是我不能發送
{ "OrgID":"1",
"UserDepartment":"1",
"WorkType":"1977",
"WorkDefinition":"EXAMPLE_EXAMPLE",
"Confirmed":[
{ "Confirmed":"qaAgo/+/j/XhECIhlAo2SQ==",
"Confirmed":"PJNd6u9RwTIwM4SRrom+mQ==",
"Confirmed":"75qFEZ7bnq+kCFvLS625Ww=="}],
"FileName":"",
"FileMimeType":"",
"FileContent":""
}
我可以發送除“已確認”以外的所有數據。
我的Java代碼在這里。
public static void sendParameter(String organizationId, String departmentId, String workType, String comfirmedList, String fileName, String fileMimeType, String fileContent, String definition) {
parameterList = new ArrayList<NameValuePair>();
parameterList.add(new BasicNameValuePair("OrgID", organizationId));
parameterList.add(new BasicNameValuePair("UserDepartment", departmentId));
parameterList.add(new BasicNameValuePair("WorkType", workType));
parameterList.add(new BasicNameValuePair("Confirmed", comfirmedList));
parameterList.add(new BasicNameValuePair("FileName", fileName));
parameterList.add(new BasicNameValuePair("FileMimeType", fileMimeType));
parameterList.add(new BasicNameValuePair("FileContent", fileContent));
parameterList.add(new BasicNameValuePair("WorkDefinition", definition));
}
如何發送確認數據?
您可以將數據手動格式化為json字符串,並將json字符串作為實體發送給請求。 在服務器端,請確保您具有與確切結構匹配的類。 例
String paramString = "{\"OrgID\":\"" + OrgID
+"\",\"UserDepartment\":\"" + UserDepartment
+"\",\"WorkType\":\"" + WorkType+ "\"}";
HttpEntity httpEntity = null;
try {
httpEntity = new StringEntity(paramString);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Content-Type", "application/json");
httpPost.setEntity(entity);
編輯
很抱歉,我的json必須是
{ "OrgID":"1",
"UserDepartment":"1",
"WorkType":"1977",
"WorkDefinition":"EXAMPLE_EXAMPLE",
"Confirmed":[
{"Confirmed":"qaAgo/+/j/XhECIhlAo2SQ==,}
{"Confirmed":"qaAgo/+/j/XhECIhlAo2SQ=="}],
"FileName":"",
"FileMimeType":"",
"FileContent":""
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.