2015-12-07 38 views
-4

我是Android新手,我不知道如何在json中發佈數據。如何使json對象以下格式發送

  { 
      "LeadId": 1, 
       "CompanyId": 2, 
       "Name": "sample string 3", 
       "CreatedBy": "1", 
       "IsAgreementGenerated": true, 
       "CustomerDc": { 
        "CustomerId": 1, 
        "AccountNo": "sample string 2", 
        "FirstName": "sample string 3", 
        "MiddleName": "sample string 4", 
        "LastName": "sample string 5", 
        "CompanyName": "sample string 6", 
        "CustomerTypeId": 7, 
        "ContactTypeId": 8, 
        "SourceId": 10, 
        "PrimaryEmail": "sample string 11", 
        "PrimaryPhone": "sample string 13", 
        "Address1": "sample string 22", 
        "CountryId": 24, 
        "StateId": 25, 
        "CityId": 26, 
        "Zipcode": "sample string 27", 
        "CompanyId": 30, 
        "IsActive": true, 
        "IsPrimaryBillingAddress": true, 
        "CreatedBy": true, 
        "CreatedDate": "2015-12-07T12:51:51.2792695+05:30" 
     } 
     } 

這是我的json數據如何將這個格式轉換成json對象。我想要這樣的動作

 JSONObject object = new JSONObject(); 
     object.put("LeadId", "1"); 
     object.put("CompanyId", "2"); 
     object.put("Name", "abhishek"); 
     object.put("CreatedBy", "1"); 
     object.put("IsAgreementGenerated", "true"); 

現在我可以做什麼我可以做下一步裏面的對象。

+0

創建另一個JSONObject的用同樣的方式不同的名稱,比如'CustomerDcJSONObject',創建'object'和'object'像'object.put添加它( 「CustomerDc」,CustomerDcJSONObject);' –

+0

抱歉,我不不明白 –

回答

0

創建customerdc jsonobject並放入對象。

JSONObject customerDcObject = new JSONObject(); 
      customerDcObject.put("CustomerId", "1"); 
      customerDcObject.put("AccountNo", "2"); 
      customerDcObject.put("FirstName", "abhishek");...//add other parameter 
object.put("CustomerDc", customerDcObject);