简体   繁体   English

如何在Android中的JSON对象内发布JSON数组

[英]How to post json array inside json object in Android

I wanna send my data to web service. 我想将数据发送到Web服务。 But i can't send 但是我不能发送

{ "OrgID":"1",
"UserDepartment":"1", 
"WorkType":"1977", 
"WorkDefinition":"EXAMPLE_EXAMPLE", 
"Confirmed":[
             {  "Confirmed":"qaAgo/+/j/XhECIhlAo2SQ==",
                "Confirmed":"PJNd6u9RwTIwM4SRrom+mQ==",
                "Confirmed":"75qFEZ7bnq+kCFvLS625Ww=="}], 
"FileName":"", 
"FileMimeType":"", 
"FileContent":"" 
} 

i can send all data except "Confirmed". 我可以发送除“已确认”以外的所有数据。

My Java codes here.. 我的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));
    }

How can i send Confirmed datas? 如何发送确认数据?

You can manually format the data as json string and sent the json string as entity to the request. 您可以将数据手动格式化为json字符串,并将json字符串作为实体发送给请求。 On the server side make sure you have a Class that matches the exact structure. 在服务器端,请确保您具有与确切结构匹配的类。 Example

    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);

EDIT 编辑

So sorry, my json must be 很抱歉,我的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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM