如何在NSDictionary中“深入”访问数据?

时间:2017-10-06 02:15:07

标签: objective-c nsdictionary

我从Web服务获得JSON响应,如下所示为NSDictionary

NSDictionary *fetchAllCollectionsJSONResponse = [NSJSONSerialization JSONObjectWithData:data
                                                                             options:0
                                                                               error:NULL];

如果我转储NSDictionary的输出,它看起来像这样

2017-10-06 10:11:46.097698+0800 NWMobileTill[396:33294] +[ShopifyWebServices fetchAllCollections]_block_invoke, {
    data =     {
        shop =         {
            collections =             {
                edges =                 (
                                        {
                        cursor = "eyJsYXN0X2lkIjo0NTI4NTY3MTcsImxhc3RfdmFsdWUiOiI0NTI4NTY3MTcifQ==";
                        node =                         {
                            description = "";
                            id = "Z2lkOi8vc2hvcGlmeS9Db2xsZWN0aW9uLzQ1Mjg1NjcxNw==";
                        };
                    },
                                        {
                        cursor = "eyJsYXN0X2lkIjo0NTI4NTkwODUsImxhc3RfdmFsdWUiOiI0NTI4NTkwODUifQ==";
                        node =                         {
                            description = "Test Collection 1";
                            id = "Z2lkOi8vc2hvcGlmeS9Db2xsZWN0aW9uLzQ1Mjg1OTA4NQ==";
                        };
                    },
                                        {
                        cursor = "eyJsYXN0X2lkIjo0NTU0OTMwMDUsImxhc3RfdmFsdWUiOiI0NTU0OTMwMDUifQ==";
                        node =                         {
                            description = Sovrum;
                            id = "Z2lkOi8vc2hvcGlmeS9Db2xsZWN0aW9uLzQ1NTQ5MzAwNQ==";
                        };
                    },
                                        {
                        cursor = "eyJsYXN0X2lkIjo0NTU0OTMzODksImxhc3RfdmFsdWUiOiI0NTU0OTMzODkifQ==";
                        node =                         {
                            description = Badrum;
                            id = "Z2lkOi8vc2hvcGlmeS9Db2xsZWN0aW9uLzQ1NTQ5MzM4OQ==";
                        };
                    }
                );
                pageInfo =                 {
                    hasNextPage = 0;
                };
            };
        };
    };
}

我需要访问此结构内部的“description”属性,我无法弄清楚如何操作。

我尝试了以下但它崩溃了

for (NSDictionary *dictionary in fetchAllCollectionsJSONResponse) {
    NSLog(@"jongel %@", [dictionary objectForKey:@"data"]);
}

2 个答案:

答案 0 :(得分:2)

@ Bilal的答案是对的。这可能更容易阅读:

TextBox BankName = gv.Controls[0].Controls[0].FindControl("txtBankname") as TextBox;
cmd.Parameters.AddWithValue("@BankName", BankName.Text );
TextBox IFSCcode = gv.Controls[0].Controls[0].FindControl("txtIfsccode") as TextBox;
cmd.Parameters.AddWithValue("@IFSCcode", IFSCcode.Text);
TextBox MICROCODE = gv.Controls[0].Controls[0].FindControl("txtMicrcode") as TextBox;
cmd.Parameters.AddWithValue("@MICROCODE",MICROCODE.Text);
TextBox BranchName = gv.Controls[0].Controls[0].FindControl("txtBranchName") as     TextBox;
cmd.Parameters.AddWithValue("@BranchName",BranchName.Text);
TextBox BankAddress = gv.Controls[0].Controls[0].FindControl("txtAddress") as TextBox;
 cmd.Parameters.AddWithValue("@BankAddress", BankAddress.Text);

答案 1 :(得分:1)

JARfetchAllCollectionsJSONResponse而不是Dictionary。试试这个。

Array