codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
func parsing() { let filePath = NSBundle.mainBundle().pathForResource("dev_info",ofType:"json") if let data = NSData(contentsOfMappedFile: filePath!) { do { dict = try NSJSONSerialization.JSONObjectWithData(data, options: .AllowFragments) as? NSArray // print("device type : \(dictionary!.valueForKey("dev_id")!)") // print("connection : \(dict!.valueForKey("port_info")!.valueForKey("connection") as! String)") self.devArray1 = NSArray() self.clientDeviceInfoArray = NSMutableArray() self.tempArray = NSArray() self.wiredArray = NSMutableArray() self.wirelessArray = NSMutableArray() devArray1 = dict print("my Dict : \(dict.valueForKey("dev_name").objectAtIndex(0) as! NSString)") } catch { print("Error!! Unable to parse ") } /* let descriptor: NSSortDescriptor = NSSortDescriptor(key: "hname", ascending: true, selector: #selector(NSString.caseInsensitiveCompare(_:))) sortedResults1 = devArray1.sortedArrayUsingDescriptors([descriptor]) print("my array :\(sortedResults1)")*/ print("device list array of dict :\(devArray1)") print("device Id Info :\(devArray1.valueForKey("dev_id").objectAtIndex(0))") print("device Name Info :\(devArray1.valueForKey("dev_name").objectAtIndex(0) as! NSString)") print("device hardware Info :\(devArray1.valueForKey("hw_ver").objectAtIndex(0) as! NSString)") print("device software Info :\(devArray1.valueForKey("sw_ver").objectAtIndex(0) as! NSString)") print("device Type Info :\(devArray1.valueForKey("dev_type").objectAtIndex(0) as! NSString)") print("device Al_Mac Info :\(devArray1.valueForKey("al_mac").objectAtIndex(0) as! NSString)") print("PORT INFO COUNT : \(devArray1.valueForKey("port_info").objectAtIndex(0).count)") print("device portInfo-->portId :\(devArray1.valueForKey("port_info").valueForKey("id")!.objectAtIndex(0).objectAtIndex(0))")//inner index :index of device print("device portInfo-->portName :\(devArray1.valueForKey("port_info").valueForKey("name")!.objectAtIndex(0).objectAtIndex(0))") print("device portInfo-->portType :\(devArray1.valueForKey("port_info").valueForKey("type")!.objectAtIndex(0).objectAtIndex(0))") print("device portInfo-->portMac :\(devArray1.valueForKey("port_info").valueForKey("mac")!.objectAtIndex(0).objectAtIndex(0))") print("portStat Count :\((devArray1.valueForKey("port_stats").objectAtIndex(0).count)!)") print("portStat for device 1 band:\(devArray1.valueForKey("port_stats").valueForKey("clients")!.valueForKey("rssi")!.objectAtIndex(0).objectAtIndex(3).objectAtIndex(0))") var noOfPorts : Int = 0 var count : Int = 0 print("port stats ssid : \(devArray1.valueForKey("port_stats").valueForKey("type")!.objectAtIndex(0).objectAtIndex(2))") for j:Int in 0 ..< self.devArray1.count { //print("client for dev id 8,port count \((devArray.valueForKey("port_stats").objectAtIndex(j).count)! as NSInteger)") noOfPorts = (devArray1.valueForKey("port_stats").objectAtIndex(j).count)! count = 0 print("Print number of ports :\(noOfPorts)") for i:Int in 0 ..< noOfPorts { let tempArr : NSMutableArray = NSMutableArray() print("portStat for id :\((devArray1.valueForKey("port_stats").valueForKey("id")!.objectAtIndex(j).objectAtIndex(i) as! NSInteger))") if( (devArray1.valueForKey("port_stats").valueForKey("type")!.objectAtIndex(j).objectAtIndex(i) as! NSString == "GE") /*|| (devArray1.valueForKey("port_stats").valueForKey("type")!.objectAtIndex(j).objectAtIndex(i) as! NSString == "")*/ ) { // print("number of clients :\((devArray1.valueForKey("port_stats").valueForKey("clients")?.objectAtIndex(j).objectAtIndex(i).count!)! as NSInteger)") print("number of objects in port stats :\(devArray1.valueForKey("port_stats").objectAtIndex(0).count)") print("number of clients :\((devArray1.valueForKey("port_stats").valueForKey("clients")?.objectAtIndex(0).objectAtIndex(0).count!)! as NSInteger)") for _:Int in 0 ..< (devArray1.valueForKey("port_stats").valueForKey("clients")?.objectAtIndex(j).objectAtIndex(i).count!)! //(devArray1.valueForKey("port_stats").valueForKey("clients")?.count)!//noOfPorts { print("client 7 array \(devArray1.valueForKey("port_stats").valueForKey("clients")?.objectAtIndex(j).objectAtIndex(i))") print("device wired") self.allClientConnectionTypeArray.addObject("wired") } } else{ for _:Int in 0 ..< (devArray1.valueForKey("port_stats").valueForKey("clients")?.objectAtIndex(j).objectAtIndex(i).count!)! { print("device wireless") self.allClientConnectionTypeArray.addObject("wireless") } } print("client detail :\((devArray1.valueForKey("port_stats").valueForKey("clients")?.objectAtIndex(j).objectAtIndex(i)))") for k:Int in 0 ..< ((devArray1.valueForKey("port_stats").valueForKey("clients")?.objectAtIndex(j).objectAtIndex(i).count)! as NSInteger) { if((devArray1.valueForKey("port_stats").valueForKey("clients")?.objectAtIndex(j).objectAtIndex(i).count)! as NSInteger != 0) { tempArr.addObject((devArray1.valueForKey("port_stats").valueForKey("clients")?.objectAtIndex(j).objectAtIndex(i).objectAtIndex(k))!) print("temp array 1: \(tempArr.objectAtIndex(k))") clientDeviceInfoArray.addObject(tempArr.objectAtIndex(k)) // clientDeviceInfoArray.insertObject(tempArr.objectAtIndex(k), atIndex: clientIndexCount) // clientIndexCount = clientIndexCount + 1 } else{ } } tempArr.removeAllObjects() // clientDeviceInfoArray.addObject(tempArr) print("Print number of ports :\(noOfPorts)") count = count + (devArray1.valueForKey("port_stats").valueForKey("clients")?.objectAtIndex(j).objectAtIndex(i).count)! as NSInteger } // self.clientCountArr.addObject(count) print("number of clients for dev_id 7 :\(count)") } print("connection array :\(self.allClientConnectionTypeArray)") print("client array count: \(clientDeviceInfoArray.count)") print("displaying client array : \(self.clientDeviceInfoArray)") print("client for dev id 7,port 0 count \((devArray1.valueForKey("port_stats").valueForKey("clients")?.objectAtIndex(0).objectAtIndex(0).count)! as NSInteger)") print("client for dev id 7,port 1 count \((devArray1.valueForKey("port_stats").valueForKey("clients")?.objectAtIndex(0).objectAtIndex(0).count)! as NSInteger)") /* let descriptor: NSSortDescriptor = NSSortDescriptor(key: "dev_name", ascending: true, selector: #selector(NSString.caseInsensitiveCompare(_:))) sortedResults1 = devArray1.sortedArrayUsingDescriptors([descriptor]) print("my array :\(sortedResults1)") ////----------- filter by wireless let predicate = NSPredicate(format:"client_type == %@","Wireless") let wirelessArray = (sortedResults).filteredArrayUsingPredicate(predicate) print(wirelessArray) //----filter by wireless*/ for x:Int in 0 ..< self.clientDeviceInfoArray.count { if self.allClientConnectionTypeArray.objectAtIndex(x) as! String=="wired" { self.wiredArray.addObject(clientDeviceInfoArray.objectAtIndex(x)) } else{ self.wirelessArray.addObject(clientDeviceInfoArray.objectAtIndex(x)) } } print("wired array : \(self.wiredArray)") print("wired array count : \(self.wiredArray.count)") print("wireless array : \(self.wirelessArray)") print("wireless count : \(self.wirelessArray.count)") self.clientTableView.reloadData() } }
Private
[
?
]
Run code
Submit