WifiInfoBean.fromJson constructor

WifiInfoBean.fromJson(
  1. dynamic json
)

Implementation

factory WifiInfoBean.fromJson(dynamic json) {
  if (json is String) {
    // 如果输入是字符串,先解析为 Map
    json = jsonDecode(json);
  }

  if (json is Map<String, dynamic>) {
    final bean = WifiInfoBean();
    bean.ssid = json['ssid']?.toString();
    bean.em = json['em']?.toString();
    bean.rssi = json['rssi'] is int
        ? json['rssi']
        : json['rssi'] != null
            ? int.tryParse(json['rssi'].toString())
            : null;
    return bean;
  }

  throw FormatException('Invalid JSON format for WifiInfoBean');
}