Nic Hubbard
Nic Hubbard

Reputation: 42173

JSON to NSDictionary literal

I need to build an NSDictionary that I can then parse with NSJSONSerialization in order to get a nice JSON formatted string.

The final output of my JSON needs to be something like:

"Viewport":{
        "BottomRight":{
            "Latitude":1.26743233E+15,
            "Longitude":1.26743233E+15
        },
        "TopLeft":{
            "Latitude":1.26743233E+15,
            "Longitude":1.26743233E+15
        }
    }

I figured it might be easiest to use NSDictionary literals, but how would I create multi-level nested dictionaries doing it this way?

Also, I will need to be setting the lat and long values when creating the dictionary.

Upvotes: 3

Views: 457

Answers (1)

Wain
Wain

Reputation: 119041

You can arbitrarily nest liberals:

@{@"Viewport":@{
    @"BottomRight":@{
        @"Latitude":@(1267...),
        @"Longitude":@(126...)
    },
    ...

Upvotes: 4

Related Questions