我有一个包含字典数组的plist。
每个字典都有几列。
我想访问字典wito for loop的每个数据。
var qplist = NSArray(contentsOfFile: path)
// qplist is array of dictionary
for meta in qplist! { //Type 'Any' does not conform to protocol 'Sequence'
//meta['test']
}
如何循环字典数组?
我想这样的东西,,,,但它不起作用。
for var meta:Dictionary in qplist! {
答案 0 :(得分:4)
尝试这样。
if let qplist = NSArray(contentsOfFile: path),
let array = qplist.objectEnumerator().allObjects as? [[String:Any]] {
for dictionary in array {
print(dictionary["test"])
}
}
答案 1 :(得分:2)
您需要这样做:
declare @cols1 varchar(max)
declare @cols2 varchar(max)
declare @query nvarchar(max)
--Row Numbers with tally
;with c1 as (
select * from ( values (1),(1),(1),(1),(1),(1),(1),(1),(1),(1)) v(n) )
,c2 as (select n1.* from c1 n1, c1 n2, c1 n3, c1 n4)
,RowNumbers as (
select top (select max(cnt) from (select cnt = count(*) from Categories group by pid ) a) convert(varchar(6), row_number() over (order by (select null))) as RowN
from c2 n1, c2 n2
)
select @cols1 = stuff((select ','+QuoteName(RowN) from RowNumbers group by RowN for xml path('')),1,1,''),
@cols2 = stuff((select ',' + QuoteName(RowN) + ' as '+ QuoteName(concat('Category' , RowN)) from RowNumbers group by RowN for xml path('')),1,1,'')
select @cols1, @cols2
Set @query = ' Select Pid, '+ @cols2 +' from ( '
Set @query += ' select *, RowN = row_number() over(partition by pid order by Category) from Categories) a '
Set @query += ' pivot (max(category) for RowN in (' + @cols1 + ')) p'
--select @query
exec sp_executesql @query