asked    Mavis     2018-10-22       ios       75 view        1 Answer

[SOLVED] How to get key Value from post webservice API and fetch that to tableview

I got data from API in this format but the problem is that I want to get all questions and answers from the API but whenever I try to get the value by using the key value it returns nil value and application crashes

this is my api data looks like after getting into a dictionary this is what my data looks like I want to show the "Options" key data into my tableView

enter image description here

here's my code for getting data from API

Alamofire.request(url, method: .post, parameters: parameters,encoding: JSONEncoding.default, headers: header ).responseJSON {
        response in
        switch response.result {
        case .success:

              print(response)

            if let result = response.result.value {

                print(result)

                let responseDict = result as! [String : Any]

                print(responseDict)


              let data = responseDict["Result"] as! [Any] 

                print(data)
            }
            break
        case .failure(let error):

            print(error)
        }
    }

  1 Answer  

        answered    Devin     2018-10-22      

You can try

if let res = responseDict["Result"] as? [[String:Any]]  {

    for item in res {

          if let ques = item["Question"] as? String  {

             print(ques)

          }

          if let op = item["Options"] as? [[String:Any]]  {

             print(op)

          }
    }
}




Your Answer





 2018-10-22         York

Facing problem with overrideredirect(True) method in tkinter on debian based Linux

I am developing an GUI using python tkinter in debian based linux.Whenever I am removing root and toplevel window title bar using overrideredirect(True) method I am facing below mentioned problems.Entry field not working(not getting focus/not getting input) when I am clicking on it.Whenever I use Alt+Tab key then only it get focused.Then I have to keep pressed mouse left or right button on clicked position then only entry field accept input otherwise input is written on terminal window.Could any one suggest an alternative way to remove titlebar or to hide title bar in tkin...
 tk                     1 answers                     53 view
 2018-10-22         Tammy

Using returned arrays

I am trying to run a procedure that takes an array called ds_out, changes values of ds_out(0) and ds(1) to either 0 or 1 depending on the state of a checkbox and returns it. I want to then output the values after the procedure but it looks like the procedure is not returning the array and printing the values in the initialising array. If you have the puts lines in the procedure it works.I've looked at tutorials and examples but I don't understand them. I want the basic of basic examples but can't find them.Below is the code I have used:global ds_outarray set ds_out {0 01 ...
 tcl                     1 answers                     52 view
 2018-10-22         Miles

zoom image on mouse scroll in angular4?

I have a piece of code which will zoomin/out on mouse scroll as shown below<!DOCTYPE html><html><body><script src='https://www.cssscript.com/demo/image-zoom-pan-mouse-interactions-zoomnpan/zoomnpan.js'></script><style>#demo { width: 460px; height: 250px; background-image: url(https://unsplash.it/3000/2000/?random); background-repeat: no-repeat; background-position: 50% 50%;}</style><div id="demo"></div><script>var p;function enable(){ p = new ZoomNPan(demo); p.minScale = 100;}enable();</script></bod...
 javascript                     2 answers                     51 view