![](/img/trans.png)
[英]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.