How to catch error while parsing json without using if for each key?
<p>here is How i parse json:</p>

<pre><code>let myObject = MyObject()
let string1 = if jsonObject["string1"] as? String{
    myObject.string1 = string1
}else{
  throw InValidJson
}

let string2 = if jsonObject["string2"] as? String{
    myObject.string2 = string2
}else{
  throw InValidJson
}

let string3 = if jsonObject["string3"] as? String{
    myObject.string3 = string3
}else{
  throw InValidJson
}
</code></pre>

<p>but that too much code, as i am using if every where, is it possible to do something like the following:</p>

<pre><code>do{
   myObject.string1 = if jsonObject["string1"] as! String
   myObject.string2 = if jsonObject["string2"] as! String
   myObject.string3 = if jsonObject["string3"] as! String

}catch(){
   error.description
}
</code></pre>

<p>so i don't need to check every key, as my json is too large.</p>

<p>Thanks</p>