0

I want to create a json structure as following:

{
    "firstName": "John",
    "lastName": "Smith",
    "address": {
        "streetAddress": "21 2nd Street",
        "city": "New York",
        "state": "NY",
        "postalCode": 10021
    },
    "phoneNumbers": [
        "212 732-1234",
        "646 123-4567"
    ]
}

Using add property method I am able to create firstName and lastName but haven't figured out how to create address and phoneNumbers in Java. Please help me out in this; Ajay

1 Answer 1

1

What you'll need to do is create a new Class called Address which has those properties (string streetAdress, city, state, postalcode). The structure itself will then have an instance of that class.

Also I wouldn't make postalCode an int. Leave it as a string.

PhoneNumbers will be a list of strings (unless you want to do something fancy with it).

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.