I have a JsonArray Object like

             JsonArray[0]= { "streetName" : "xyz", "wardName" : "12xz"}
             JsonArray[1]= { "doorNumber" : "123", "plot" : "90z"}
             JsonArray[2]= { "city" : "pqr", "district" : "nmc"}
             JsonArray[3]= { "state" : "hisd", "country" : "kasps"}

I want to convert above JsonArray into JsonObject which will be like

{
    "addresss":[ {
        "streetName": "xyz",
        "wardName": "12xz",
        "doorNumber": "123",
        "plot": "90z",
        "city": "pqr",
        "district": "nmc",
        "state": "hisd",
        "country": "kasps"
    }]
}

I tried in different ways using Json Objcet put and traversing JSONarray and appending the value to String builder. No use. any one give me some idea. how to do that. Thanks for your help.

share|improve this question
    
what you have is not a jsonarray but an array of json objects – Scary Wombat 2 hours ago
    
    
Possible duplicate of Accessing members of items in a JSONArray with Java – Jobin 2 hours ago
    
Hi, Thanks for your replay. can you check now, I want the Json Object like that – javabrain 2 hours ago
    
Thank you Jobin, but in this array of Json objects have different keys with different values – javabrain 2 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.