0

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.

javabrain
  • 11
  • 2
  • what you have is not a jsonarray but an array of json objects – Scary Wombat Nov 18 '16 at 05:00
  • see http://stackoverflow.com/a/10593838/2310289 – Scary Wombat Nov 18 '16 at 05:02
  • Possible duplicate of [Accessing members of items in a JSONArray with Java](http://stackoverflow.com/questions/1568762/accessing-members-of-items-in-a-jsonarray-with-java) – Jobin Nov 18 '16 at 05:02
  • Hi, Thanks for your replay. can you check now, I want the Json Object like that – javabrain Nov 18 '16 at 05:19
  • Thank you Jobin, but in this array of Json objects have different keys with different values – javabrain Nov 18 '16 at 05:21
  • StringBuilder usually works for this kind of situation....What error or difficulties are you having when using `StringBuilder` – Nirmal Raj Nov 18 '16 at 05:28
  • HI Nirmal Raj, Thank you for your reply. I tried with String Builder. while appending { } also appending. like "addresss":[ { "streetName": "xyz", "wardName": "12xz"} { "doorNumber": "123", "plot": "90z"} {"city": "pqr", "district": "nmc"} {"state": "hisd", "country": "kasps"} }] – javabrain Nov 18 '16 at 05:48

0 Answers0