Swiftyjson: How do I create new JSON objects ?!

Created on 18 Aug 2016  路  2Comments  路  Source: SwiftyJSON/SwiftyJSON

Hello

I'm trying to create a JSON object like this

[ null, { "name": "nameExample", "age": 45 }, { "name": "anotherName", "age": 55 } ]

And eventually get that JSON object as a string.
How can do so ?!

Most helpful comment

I am making some playground docs in #613 .
And I write below the part of source that I used to make JSON.

In swift, you need to write to make JSON object directly as Dictionary type using [ ] instead of { }.

var jsonArray: JSON = [
    "array": [12.34, 56.78],
    "users": [
        [
            "id": 987654,
            "info": [
                "name": "jack",
                "email": "[email protected]"
            ],
            "feeds": [98833, 23443, 213239, 23232]
        ],
        [
            "id": 654321,
            "info": [
                "name": "jeffgukang",
                "email": "[email protected]"
            ],
            "feeds": [12345, 56789, 12423, 12412]
        ]
    ]
]

All 2 comments

I am making some playground docs in #613 .
And I write below the part of source that I used to make JSON.

In swift, you need to write to make JSON object directly as Dictionary type using [ ] instead of { }.

var jsonArray: JSON = [
    "array": [12.34, 56.78],
    "users": [
        [
            "id": 987654,
            "info": [
                "name": "jack",
                "email": "[email protected]"
            ],
            "feeds": [98833, 23443, 213239, 23232]
        ],
        [
            "id": 654321,
            "info": [
                "name": "jeffgukang",
                "email": "[email protected]"
            ],
            "feeds": [12345, 56789, 12423, 12412]
        ]
    ]
]

There hasn't much activity on this issue for a while so I'll go ahead and consider it fixed. Let me know if you'd like me to reopen it. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joernroeder picture joernroeder  路  4Comments

MrLoveQD picture MrLoveQD  路  5Comments

amit-bhavsar picture amit-bhavsar  路  5Comments

posixrails picture posixrails  路  6Comments

ejpusa picture ejpusa  路  5Comments