Ok, this is my struct and the list, the real one:
struct Wifi: Codable {
var SSID: String
var bSSID: String
var Channel: Int
var Band: String
var Width: String
var noise: Int
var rssi: Int
var qualitySNR: Int
var isConnected: Bool
init() {
SSID = ""
bSSID = "00:00:00:00:00:00"
Channel = 0
Band = ""
Width = ""
rssi = 0
noise = 0
qualitySNR = 0
isConnected = false
}
}
var wifiList: [Wifi] = []
Here is how I do populate it:
wifiList.removeAll(keepingCapacity: false)
//... get all stuff from the network and insert into the list
// wifi is declared as wifi = Wifi.init()
wifiList.insert(wifi, at: 0)
After the list if completed I convert it string, as I showed before:
func convertToJSONString() -> String {
let encoder = JSONEncoder()
let data = try! encoder.encode(wifiList)
return String(data: data, encoding: .utf8)!
}
What I get:
[{"bSSID":"00:00:00:00:00:00","Band":"2Ghz","rssi":-77,"SSID":"CLARO_2GA37FE4","Channel":6,"isConnected":false,"Width":"40MHz","noise":76,"qualitySNR":-153},{"bSSID":"00:00:00:00:00:00","Band":"2Ghz","rssi":-74,"SSID":"2.4G DEMOLIDOR HELMAR LUAN","Channel":8,"isConnected":false,"Width":"40MHz","noise":76,"qualitySNR":-150},{"bSSID":"00:00:00:00:00:00","Band":"5Ghz","rssi":-88,"SSID":"TP-LINK_9562_5G","Channel":157,"isConnected":false,"Width":"80MHz","noise":76,"qualitySNR":-164},{"bSSID":"00:00:00:00:00:00","Band":"5Ghz","rssi":-77,"SSID":"AP 71 A-5G","Channel":52,"isConnected":false,"Width":"80MHz","noise":76,"qualitySNR":-153},{"bSSID":"00:00:00:00:00:00","Band":"5Ghz","rssi":-48,"SSID":"XIMA","Channel":157,"isConnected":true,"Width":"80MHz","noise":76,"qualitySNR":-124},{"bSSID":"00:00:00:00:00:00","Band":"5Ghz","rssi":-83,"SSID":"5.G DEMOLIDOR HELMAR LUAN","Channel":48,"isConnected":false,"Width":"80MHz","noise":76,"qualitySNR":-159},{"bSSID":"00:00:00:00:00:00","Band":"2Ghz","rssi":-61,"SSID":"LIMA_2G","Channel":10,"isConnected":false,"Width":"40MHz","noise":76,"qualitySNR":-137},{"bSSID":"00:00:00:00:00:00","Band":"2Ghz","rssi":-76,"SSID":"Net-Virtua-9095-2.4G","Channel":1,"isConnected":false,"Width":"40MHz","noise":76,"qualitySNR":-152},{"bSSID":"00:00:00:00:00:00","Band":"2Ghz","rssi":-84,"SSID":"#NET-CLARO-WIFI","Channel":1,"isConnected":false,"Width":"40MHz","noise":76,"qualitySNR":-160},{"bSSID":"00:00:00:00:00:00","Band":"2Ghz","rssi":-91,"SSID":"Renato.2G","Channel":11,"isConnected":false,"Width":"40MHz","noise":76,"qualitySNR":-167},{"bSSID":"00:00:00:00:00:00","Band":"5Ghz","rssi":-78,"SSID":"AP 71 A","Channel":52,"isConnected":false,"Width":"80MHz","noise":76,"qualitySNR":-154},{"bSSID":"00:00:00:00:00:00","Band":"2Ghz","rssi":-85,"SSID":"Vila Mariana","Channel":1,"isConnected":false,"Width":"40MHz","noise":76,"qualitySNR":-161}]
[{"bSSID":"00:00:00:00:00:00","Band":"5Ghz","rssi":-52,"SSID":"XIMA","Channel":157,"isConnected":false,"Width":"80MHz","noise":80,"qualitySNR":-132}]
In this example, the last item shouldn't be "out" of the array. The result shows like 2 arrays and I expect to have only one.