raj kumar raj kumar - 10 months ago 43
iOS Question

parsing json data in for loop statement using swift 2

I am developing a app using swift2 am parsing JSON data to a

which works perfectly when click on the cell it moves to other view controller and fetching some data to label box. The problem is when I clicks any cells on the table view it fetching same data to a view controller I dont know how to parse the data into for loop statement.

Json data(data am recieving from the server):

item: [
name: "name1",
id: "1",
name: "name2",
id: "2"

Code what I have tried:

created outlet labelname and labelid

var arrDict :NSMutableArray=[]
let urlstring = "www.anything.com"
let url = NSURL(string: urlString)
let data = try? NSData(contentsOfURL: url, options: [])
let json = JSON(data: data)

//it helps to print all the json data in console

Now help me work with forloop statement

Answer Source

Try this,it helps you:-

 for (_, subjson): (String, JSON) in json["item"]{

     print("YOUR SUBJSON VALUE>> \(subjson["name"].stringValue)")