objective c - Finding keys/Values from nested NSDictionary -


i have file located @ /users/admin/desktop/wi-fi.txt, contains follows... wi-fi:

  software versions:       corewlan: 4.3.2 (432.47)       corewlankit: 3.3.2 (332.36)       menu extra: 9.3.2 (932.35)       system information: 9.0 (900.8)       io80211 family: 6.3 (630.35)       diagnostics: 3.0 (300.40)       airport utility: 6.3.2 (632.3)   interfaces:     en1:       card type: airport extreme  (0x14e4, 0x10e)       firmware version: broadcom bcm43xx 1.0 (5.106.98.100.22)       mac address: a8:86:dd:a9:6d:13       locale: apac       country code: in       supported phy modes: 802.11 a/b/g/n       supported channels: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 36, 40, 44, 48, 52, 56, 60, 64, 149, 153, 157, 161, 165       wake on wireless: supported       airdrop: supported       status: connected       current network information:         ddl2:           phy mode: 802.11n           bssid: c8:d7:19:62:1e:46           channel: 6           country code: in           network type: infrastructure           security: wpa2 personal           signal / noise: -59 dbm / -86 dbm           transmit rate: 52           mcs index: 11       other local wi-fi networks:         ddl:           phy mode: 802.11g           bssid: 00:1b:2f:df:04:bc           channel: 10           network type: infrastructure           security: wep           signal / noise: -57 dbm / -84 dbm         ddl3:           phy mode: 802.11n           bssid: 28:c6:8e:dc:c8:db           channel: 3           network type: infrastructure           security: wpa2 personal           signal / noise: -56 dbm / -85 dbm         ddl4:           phy mode: 802.11n           bssid: 40:16:7e:a2:3c:b4           channel: 149,+1           network type: infrastructure           security: wpa2 personal           signal / noise: -50 dbm / -92 dbm         ddl4:           phy mode: 802.11n           bssid: 40:16:7e:a2:3c:b0           channel: 6           network type: infrastructure           security: wpa2 personal           signal / noise: -47 dbm / -81 dbm         netgear:           phy mode: 802.11g           bssid: 00:24:b2:bc:32:62           channel: 1           network type: infrastructure           security: wep           signal / noise: -84 dbm / -84 dbm         rs001:           phy mode: 802.11g           bssid: b0:48:7a:c9:d8:f6           channel: 11           country code: in           network type: infrastructure           security: wpa personal           signal / noise: -44 dbm / -90 dbm         rs002:           phy mode: 802.11g           bssid: b0:48:7a:c9:d9:04           channel: 12           country code: in           network type: infrastructure           security: wpa personal           signal / noise: -51 dbm / -90 dbm         rs003:           phy mode: 802.11g           bssid: 00:1f:33:b4:99:2c           channel: 11           network type: infrastructure           security: wpa personal           signal / noise: -67 dbm / -90 dbm         fortinet_captive_portal:           phy mode: 802.11n           bssid: 1a:5b:0e:39:57:b2           channel: 6           country code: in           network type: infrastructure           security: none           signal / noise: -85 dbm / -81 dbm         testlab:           phy mode: 802.11n           bssid: 08:5b:0e:39:57:b2           channel: 6           country code: in           network type: infrastructure           security: wpa/wpa2 personal           signal / noise: -83 dbm / -81 dbm 

i want information each wifi network name , noise / strength.can body tell me how it.

not sure if understand question. try make little bit more clear.

anyway, here's think understood.

nsstring *path = [[nsbundle mainbundle] pathforresource:@"/users/admin/desktop/wi-fi" oftype:@"txt"]; nsarray *categories = [nsarray arraywithcontentsoffile:path]; (nsdictionary *category in categories) {     nslog(@"%@", [category objectforkey:@"interfaces"]);     nslog(@"%@", [category objectforkey:@"software versions"]); } 

i haven't ran think should work, give shot. similar you're looking for. if not, it's in right direction , brings step closer finding answer. happy coding!

edit:

drag text file project , following

nsstring *path = [[nsbundle mainbundle] pathforresource:@"nsdictionarytextfile" oftype:@"txt"]; nsstring *content = [nsstring stringwithcontentsoffile:path encoding:nsutf8stringencoding error:null]; nsarray *testarray = [content componentsseparatedbystring:@"\n"]; nsstring *topdictionary = @""; nsmutabledictionary *dict = [nsmutabledictionary dictionary]; nsmutabledictionary *finaldict = [nsmutabledictionary dictionary]; for(nsstring *s in testarray){     nsarray *newarray = [s componentsseparatedbystring:@":"];     if([newarray[1] isequaltostring:@""]){         if([dict count] == 0){             topdictionary = newarray[0];         }         else{             topdictionary = [topdictionary stringbytrimmingcharactersinset:[nscharacterset whitespaceandnewlinecharacterset]];             [finaldict setobject:[dict copy] forkey:[topdictionary copy]];             [dict removeallobjects];         }     } else{         nsstring *object = [newarray[1] stringbytrimmingcharactersinset:[nscharacterset whitespaceandnewlinecharacterset]];         nsstring *key = [newarray[0] stringbytrimmingcharactersinset:[nscharacterset whitespaceandnewlinecharacterset]];         [dict setobject:object forkey:key];     } } topdictionary = [topdictionary stringbytrimmingcharactersinset:[nscharacterset whitespaceandnewlinecharacterset]]; [finaldict setobject:dict forkey:topdictionary]; nslog(@"finaldict: %@", finaldict); 

* please not not finished ! have figure out more logic *

don't know how want them should give on how should work. didn't figure out complete logic adding top level dictionary , sub level dictionary should put in right directions. start removing trimming put in top dictionary , check empty/white space in front of string , use figure out dictionary supposed go. ie no empty space means highest 1 , more white spaces "inner" in dictionary. hope helps started.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -