title: How to convert JSON String to JSON Object in swift?
body: <p>I trying to generate JSON Object and convert that to JSON String and that process is Successfully placed. But my real problem rises when I try to convert JSON String to JSON Object. When I try I get nil as result.</p>
  
  <pre><code>func generateJSONObject() {
          let jsonObject = createJSONObject(firstName: firstName[0], middleName: middleName[0], lastName: lastName[0], age: age[0], weight: weight[0])
          print("jsonObject : \(jsonObject)")
  
          let jsonString = jsonObject.description // convert It to JSON String
          print("jsonString : \(jsonString)")
  
          let jsonObjectFromString = convertToDictionary(text: jsonString)
          print("jsonObjectFromString : \(String(describing: jsonObjectFromString))")
  
      }
  </code></pre>
  
  <h1>createJSONObject func</h1>
  
  <pre><code>// JSON Object creation
      func createJSONObject(firstName: String, middleName: String, lastName: String, age: Int, weight: Int) -&gt; [String: Any] {
  
          let jsonObject: [String: Any] = [
              "user1": [
                  "first_name": firstName,
                  "middle_name": middleName,
                  "last_name": lastName,
                  "age": age,
                  "weight": weight
              ]
          ]
          return jsonObject
      }
  </code></pre>
  
  <h1>convertToDictionary func</h1>
  
  <pre><code>func convertToDictionary(text: String) -&gt; [String: Any]? {
          if let data = text.data(using: .utf8) {
              do {
                  return try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any]
              } catch {
                  print(error.localizedDescription)
              }
          }
          return nil
      }
  </code></pre>
  
  <h1>Logs</h1>
  
  <ol>
  <li>When I print <code>JSON</code> Object I get </li>
  </ol>
  
  <p>jsonObject : ["user1": ["age": 21, "middle_name": "Lazar", "last_name": "V", "weight": 67, "first_name": "Alwin"]]</p>
  
  <ol start="2">
  <li><p>When I print <code>JSON</code> String I get</p>
  
  <p>jsonString : ["user1": ["age": 21, "middle_name": "Lazar", "last_name": "V", "weight": 67, "first_name": "Alwin"]]</p></li>
  <li><p>Convert <code>JSON</code> String to <code>JSON</code> Object I get below error</p>
  
  <p>The data couldn’t be read because it isn’t in the correct format.</p>
  
  <p>jsonObjectFromString : nil</p></li>
  </ol>
  
  <p>I don't know why this happening. I want to convert <code>JSON</code> String to <code>JSON</code> Object and I want to parse the <code>JSON</code>.</p>