user1042895
user1042895

Reputation: 1

To create JsonArray

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

Upvotes: 0

Views: 204

Answers (1)

Haedrian
Haedrian

Reputation: 4328

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).

Upvotes: 1

Related Questions