0

I am trying to get an JSON Array, which is looks like this

[
  {
    "number": "111-1001"
  },
  {
    "number": "111-1002"
  },
  {
    "number": "111-1003"
  }
]

For parsing this i write this code:

    let registeredNumberUrl = "http://myURL"
    let url = URL(string: registeredNumberUrl)
    do {


        let allregisteredNumber = try Data(contentsOf: url!)


        let jsonResult = try JSONSerialization.jsonObject(with: allregisteredNumber , options: []) as? [[String:Any]]

        print("jsonResult \(jsonResult?.count)")

    } catch let error as NSError{
        print(" !!!!  registered was not succeded  !!!! \(error)")

    }        
}

But I'm getting this error:

    Error Domain=NSCocoaErrorDomain
 Code=3840
 "No value for key in object around character 41." 
UserInfo={NSDebugDescription= No value for key in object around character 41.
}

I have tried some solution like this SWIFT 2: Loop through JSON array but I'm keep getting the same error:

5
  • The issue is related to the JSON rather than to the code. This JSON is valid. But if it looks like, it's not the actual JSON so how should we know? ... Commented Apr 9, 2017 at 12:31
  • The error's pretty clear: "No value for key in object around character 41." Look at the JSON and count the characters: There is no value for key regNumbers. Commented Apr 9, 2017 at 12:36
  • but when i am checking my link in Postman it gives me the right output of json. Commented Apr 9, 2017 at 12:43
  • 1
    Then maybe there are invalid characters which need to be escaped on the server-side. Commented Apr 9, 2017 at 12:46
  • Thanks @vadian it was the error from the server . Commented Apr 9, 2017 at 13:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.