从iOS中的NSArray检索数据
我对这个很陌生。我已将所有从iOS中的NSArray检索数据,ios,objective-c,nsarray,Ios,Objective C,Nsarray,我对这个很陌生。我已将所有NSDictionary存储到NSArray中,现在我要检索数据。我不知道怎么做。请帮我做这个。我想获取密钥和数据,并基于此在UITableView中显示数据。我有所有的东西,只有检索部分待定 下面是我的NSArray: { Code = MCP3441G; "Needle Description" = "1/2 Circle Round Body MH"; "Needle Dimension" = "31 MM"; "No. of f
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;
},
有几种访问数据的方法。首先,我建议您查看NSArray()和NSDictionary()的文档 要访问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
一旦有了字典,就有许多可能的方法来访问密钥和数据。如果您有密钥并且需要特定的值,可以执行以下操作:
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:@“针描述”]
)
您还可以获取所有键的数组(如您在问题中所述,用于在表中列出),但执行以下操作:
NSArray *keys = [dict allKeys];
然后,您可以循环遍历这些键,并逐项轮询值
同样,查看文档,了解更多获取信息的方法