title: Get JSON value to Array
body: <p>I need to get the JSON value from MYSQL and display it in the table view. I have done PHP part to receive data but I have error with my XCODE. My data will store temperature, humidity and digital status (on off) of sensor. I have questions below:</p>
  
  <ol>
  <li>How to get ON/OFF JSON value and store in Bool array?</li>
  <li>How to get JSON value and store in Float array?</li>
  <li>if JSON value is , how can I store value as 0 in XCODE?</li>
  </ol>
  
  <hr>
  
  <pre><code>class DataManager {
    var nodenameArray: [String] = []
    var nodeidArray: [String] = []
    var tempArray: [Float] = []
    var humArray: [Float] = []
    var pirArray: [Bool] = []
    var lightArray: [Bool] = []
    var relayArray: [Bool] = []
    var hallArray: [Bool] = []
    var smokeArray: [Bool] = []
  
    @objc func taskdo() {
      self.nodenameArray = []
      self.nodeidArray = []
      self.tempArray = []
      self.humArray = []
      self.pirArray = []
      self.lightArray = []
      self.relayArray = []
      self.hallArray = []
      self.smokeArray = []
  
      if userlogin == true {
        let request = NSMutableURLRequest(url: NSURL(string: http://talectric.com/wp-admin/a_p/iot/read_all.php")! as URL)
          request.httpMethod = "POST"
          let postString = "username=\(username)&amp;password=\(password)&amp;authen=wdwfesf9329140dsvfxkciospdkm"
  
          request.httpBody = postString.data(using: String.Encoding.utf8)
  
          let task = URLSession.shared.dataTask(with: request as URLRequest) {
              data, response, error in
              if error != nil {
                  print("error=\(error!)")
                  return
              } else {
                  do {
                      if let respondString = try JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? NSDictionary {
                          print(respondString)
                          if let nodedata = respondString.value(forKey: "nodedata") as? NSArray {
                              for node in nodedata{
                                  if let nodeDict = node as? NSDictionary {
                                      if let nodeid = nodeDict.value(forKey: "node_id") {
                                          self.nodeidArray.insert(nodeid as! String, at: 0)
                                      }
                                      if let nodeid = nodeDict.value(forKey: "node_name") {
                                          self.nodenameArray.insert(nodeid as! String, at: 0)
                                      }
                                      if let nodeid = nodeDict.value(forKey: "temp") {
                                          self.tempArray.insert(Float(nodeid as! String)!, at: 0)
                                      }
                                      if let nodeid = nodeDict.value(forKey: "hum") {
                                         print(nodeid)
                                          self.humArray.insert(Float(Int(nodeid as! String)!), at: 0)                
                                      }
                                  }
                              }
                          }
                      }
                      print(self.nodenameArray)
                      print(self.nodeidArray)
                      print(self.tempArray)
                      print(self.humArray)
                      NotificationCenter.default.post(name: NSNotification.Name(rawValue: "load"), object: nil)
                  }
                  catch let error as NSError {
                      print(error.debugDescription)
                  }
              }
          }
          task.resume()
      }
    }
  }
  </code></pre>
  
  <p>below is the respond: </p>
  
  <pre><code>{
      nodedata =     (
              {
  
          "hall_status" = "&lt;null&gt;";
  
          hum = 111;
  
          "light_status" = "&lt;null&gt;";
  
          "node_id" = y2cfwecrw3hqznuxmfvf;
  
          "node_name" = SVIN03;
  
          "pir_status" = OFF;
          "relay_status" = "&lt;null&gt;";
          "smoke_status" = "&lt;null&gt;";
          temp = 2132;
      },
              {
          "node_name" = SVIN04;
          nodeid = aj2w1aljw8nd65ax79dm;
      },
              {
          "hall_status" = "&lt;null&gt;";
          hum = 100;
          "light_status" = "&lt;null&gt;";
          "node_id" = mwmfl2og2l8888fjpj2d;
          "node_name" = SVIN05;
          "pir_status" = ON;
          "relay_status" = "&lt;null&gt;";
          "smoke_status" = "&lt;null&gt;";
          temp = 45;
      }
  );
  numberofnodeid = 3;
  }
  </code></pre>
  
  <p>111
  100</p>
  
  <blockquote>
    <p>Could not cast value of type '__NSCFNumber' (0x10db6f878) to 'NSString' (0x10ca71568).
    2018-10-11 08:11:05.352491+0700 IOT 2[1506:101847] Could not cast value of type '__NSCFNumber' (0x10db6f878) to 'NSString' (0x10ca71568).</p>
  </blockquote>
  
  <p>error is in this line : </p>
  
  <p><code>self.humArray.insert(Float(Int(nodeid as! String)!), at: 0)</code></p>