我对此很新。我已将所有NSDictionary
存储到NSArray
,现在我想要检索数据。我不知道该怎么做。请帮帮我。我希望获得密钥和数据,并希望在UITableView
中显示数据。我有所有东西只检索部分正在等待。
以下是我的NSArray
:
{
Code = MCP3441G;
"Needle Description" = "1/2 Circle Round Body MH";
"Needle Dimension" = "31 MM";
"No. of foils per box" = 12;
"Per box maximum retail price" = 7440;
"Per box price to retailers & hospitals" = 5474;
Size = "2/0";
"Suture type and length" = "MONOCRYL monofilament 70 CM Violet";
nid = 86;
},
{
Code = NW1641;
"Needle Description" = "1/2 Circle Round Body";
"Needle Dimension" = "30 MM";
"No. of foils per box" = 12;
"Per box maximum retail price" = 4800;
"Per box price to retailers & hospitals" = 3510;
Size = "2/0 Only";
"Suture type and length" = "MONOCRYL Undyed Monofilament 70 CM";
nid = 86;
},
{
Code = NW1642;
"Needle Description" = "1/2 Circle Round Body";
"Needle Dimension" = "30 MM";
"No. of foils per box" = 12;
"Per box maximum retail price" = 4800;
"Per box price to retailers & hospitals" = 3510;
Size = "1/0";
"Suture type and length" = "MONOCRYL Undyed Monofilament 70 CM";
nid = 86;
},
{
Code = NW1648;
"Needle Description" = "3/8 Circle Round Body";
"Needle Dimension" = "16 MM";
"No. of foils per box" = 12;
"Per box maximum retail price" = 3600;
"Per box price to retailers & hospitals" = 2687;
Size = "4/0";
"Suture type and length" = "MONOCRYL Undyed Monofilament 70 cm";
nid = 86;
},
{
Code = NW1663;
"Needle Description" = "1/2 Circle Oval Round Body J.B";
"Needle Dimension" = "22 MM";
"No. of foils per box" = 12;
"Per box maximum retail price" = 5280;
"Per box price to retailers & hospitals" = 3870;
Size = "3/0";
"Suture type and length" = "MONOCRYL Undyed Monofilament 70 CM";
nid = 86;
},
{
Code = NW1664;
"Needle Description" = "1/2 Circle Oval Round Body J.B";
"Needle Dimension" = "26 MM";
"No. of foils per box" = 12;
"Per box maximum retail price" = 5880;
"Per box price to retailers & hospitals" = 4347;
Size = "3/0";
"Suture type and length" = "MONOCRYL Undyed Monofilament 70 CM";
nid = 86;
},
答案 0 :(得分:1)
有几种方法可以访问数据。首先,我建议您查看NSArray(https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/)和NSDictionary(https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/)的文档
要访问NSArray的某个元素,您可以执行以下操作:
NSDictionary *dict = (NSDictionary*) myArray[0]; //gets the first item of the array.
获得字典后,有许多方法可以访问密钥和数据。如果您有密钥并且想要特定值,则可以执行以下操作:
NSString *desc = dict[@"Needle Description"]; //gets the value for the key Needle Description
(注意上面使用的是速记 - 你也可以做更详细的[dict objectForKey:@"Needle Description"]
)
您还可以获取所有键的数组(用于在表格中列出,如您在问题中所述),但执行以下操作:
NSArray *keys = [dict allKeys];
然后,您可以遍历这些键,并逐项轮询值。
再次,查看文档以了解更多获取信息的方法。