1

When I try to Parse a JSON object,

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

I get an error saying that

Cannot invoke 'jsonObject' with an argument list of type 'with:([String:Any]), options:[Any]'

Here is my reportData in JSON format, obtained from Server

{
    "status": "success",
    "statusCode": 200,
    "message": "Report exists",
    "patientReport": {
        "caseId": "case040784",
        "Observations": "These are test observations",
        "userUid": "MY5FDbl0bgZStAY5Ky6OtYAzbDT2",
        "nextSteps": "Here are my next steps",
        "customerUid": "customerUid",
        "results": {
            "test1": "12",
            "test3": "15",
            "test3": "12"
        }
    }
}

Could someone please guide me where I am going wrong.

1
  • 1
    Seems your jsonData is already a Swift Dictionary of type [String: Any]. You have no need to parse it. Just use it as a Swift Dictionary. Commented Jul 11, 2017 at 1:52

2 Answers 2

2

This function:

jsonObject(with: Data, options: JSONSerialization.ReadingOptions = [])

requires two parameters with type Data and JSONSerialization.ReadingOptions.

Your reportData is Dictionary not a Data. So you can use it without parse to Dictionary.

Sign up to request clarification or add additional context in comments.

Comments

0

Cannot invoke 'jsonObject' with an argument list of type 'with:([String:Any]), options:[Any]'

I think this may be the strangest thing I've seen today.

Reading this message literally says that reportData is of type ([String: Any])—A tuple containing a single value [String: Any].

After reading Creating Tuples For a Single Value, I see there is no difference between ([String: Any]) and [String: Any].

The other users have already answered it… You don't need to parse the already dictionary object, I just found the tuple thing intresting.

Comments

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.