当前位置: 动力学知识库 > 问答 > 编程问答 >

arrays - cast dictionary elements of different types

问题描述:

I am using such code to get JSON from server:

var jsonresult = NSArray()

do {

jsonresult = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers) as! NSArray

}

It helps me to get an array of dictionaries in jsonresult variable.

Then I am looping through array to add all dictionaries to another array.

for i in jsonresult {

print(i)

self.otherArray.append(i as! Dictionary<String, AnyObject>)

}

I am using Dictionary type because there are strings values as well as Double values.

Problem is that after data is inserted I can not use "double" values. I get such error: Could not cast value of type 'NSTaggedPointerString' (0x10c472860) to 'NSNumber'

Yes, I know that I can use (value as! NSString).doubleValue but it would be better to cast NSTaggedPointerString into NSNumber in the begining.

Any ideas how can I do it? Maybe I can cast each element of dictionary while adding them to self.otherArray?

分享给朋友:
您可能感兴趣的文章:
随机阅读: