Assuming [{"id":"1", "name":"Kakkad", "cont":"9714494770"},{"id":"2", "name":"Ashish", "cont":"9714494770"}]
is assigned to a property named jsonData.
let sampleJSON = JSON(data: jsonData)
let sampleArray = sampleJSON.array
sampleArray is an optional array of JSON objects.
let firstDict = sampleArray[0]
firstDict is an optional JSON dict.
let name = firstDict["name"]
is an optional JSON object
let virtName = name.string
is a optional string (In this case "Kakkad").
let realName = name.stringValue
realName is a string or an empty string.
You could also use:
let longName = sampleJSON[0]["name"].stringValue
After you initialize the JSON object with data all of the elements are JSON types until you convert them to a swift type.
- .string optional (string or null)
- .stringValue string or "" empty
string
- .dict optional ([String: AnyObject] or null)
- .dictValue
([String: AnyObject] or String: AnyObject)
“ ... ”
:) – Liscomb