0

I have a JSON which is mentioned below.

 {"Orders"
   [{"BusinessUnit":"TS",
     "DeliveryDetails":
             [{"SlotStartDateTime":"2015-03-30T16","DeliveryOption":"Home    
             Delivery","ReservationID":"13349259","PersonInfoShipTo":
             {"Address":"OrganizationName":"HP","BuildingTypeID":"",
             "IsCommercialAddress":"false","PostalCode":"56001",
             "City":"Bangalore","AddressLine3":"A3","AddressLine2":"A2",
             "AddressLine1":"A1","IsPAFValidated":"true",
             "GridRef":"0473601734","State":"KA","AddressLine4":"A4",
             "Country":"IN"}},"ShipNode":"NODEUK","SlotEndDateTime":"2015-
              03-30T17"}],
    "FulfilmentID":"a9466f83-938d-4115-a3d4-62ff4bdcd1b6",
    "OrderTypeIndicator":"SalesOrder"}]}

Question: I am able to take the values of BusinessUnit, FulfilmentID & OrderTypeIndicator. But, I am unable to take the values present inside the inner json object DeliveryDetails. Could anyone help me on taking those values

3
  • share your code which is unable to access DeliveryDetails Commented Mar 26, 2015 at 19:03
  • 1
    JsonObject.get("DeliveryDetails") whill return you JSONArray not JSONObject Commented Mar 26, 2015 at 19:05
  • thanks Pravin n Lentz.. I am using Json.Simple jar for this operation. But, I am unable to achieve what you have suggested. Could you please guide me with the correct jar..?. I am very new to this. Commented Apr 2, 2015 at 8:24

1 Answer 1

2

"DeliveryDetails" is mapped to a json array object with a single json object inside.

Try doing:

json.getJSONArray("Orders").get(0).get("DeliveryDetails").get(0)

Of course it would be better to check first if keys exists and the size of json arrays returned before retrieving actual indices.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.