0

I have an iOS Application which makes a POST request to a server. In the body I have to add metadata in JSON format.

The JSON I have to send is this:

{
            "snippet": {
                "title": {VIDEO TITLE},
                "description": {VIDEO DESCRIPTION},
                "tags": [{TAGS LIST}],
                "categoryId": {YOUTUBE CATEGORY ID}
            },

            "status": {
                "privacyStatus": {
                    "public", "unlisted" OR "private"
                }
            }
         }

I have tried creating the JSON in a NSDictionary like this, but it doesn't seem to work:

NSDictionary *metadat = @{@"snippet" : @"{",
                                    @"title" : @"test_name",
                                    @"description": @"test_desc",
                                    @"tags": @"[test]",
                                    @"categoryId" : @"{1111}",
                                  @"}",

                                    @"status" : @"{",
                                        @"privacyStatus" : @"{",
                                            @"public",
                                        @"}",
                                    @"}",
                                  @"}"};

What am I doing wrong? I have followed the structure of the JSON format.

Thank you for your time, Dan.

1 Answer 1

3

You don't add the { to the dictionary, but just add another NSDictionary.

But the example JSON is not really valid JSON, the privacyStatus seems a bit weird.

Something like:

NSDictionary *metadat = @{@"snippet" : @{
                                  @"title" : @"test_name",
                                  @"description": @"test_desc",
                                  @"tags": @[@"test"],
                                  @"categoryId" : @"{1111}",
                                  },
                          @"status" : @{
                                  @"privacyStatus" : @"public"
                                },
                          };
Sign up to request clarification or add additional context in comments.

4 Comments

So you can nest a NSDictionary inside another NSDictionary?
Ofcourse why not? just as you can nest an array in an array/dictionary/
Ah ok. Thank you. Let me give this a try. This JSON block is actually begin sent to YouTube and they require "privacyStatus"...
No I don't mean that the node is weird, just the fast you can not have something like "hello":{"name"} in JSON. It should be "hello":name" or "hello":{"key" : "value"}

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.