Error creating JSON object

I’m getting an error when trying to serialize jsonData to an object:

let jsonObject = try JSONSerialization.jsonObject(with: jsonData, options: [])

The error message:

Error creating JSON object: Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}

The jsonString contains:

jsonFlickrApi({"photos":{"page":1,"pages":5,"perpage":100,"total":500,"photo":[{"id":"36025534193","owner":"126755884@N06","secret":"30da222934","server":"4376","farm":5,"title":"Broken Nature","ispublic":1,"isfriend":0,"isfamily":0,"datetaken":"2015-07-25 18:45:00","datetakengranularity":"0","datetakenunknown":"0","url_h":"https:\/\/farm5.staticflickr.com\/4376\/36025534193_d7d76fee8f_h.jpg","height_h":1064,"width_h":"1600"},....

Please help!

Solved!

It was a typo in the baseParams:

let baseParams = [
            "method" : method.rawValue,
            "format" : "json",
            **"nojsoncallbak" : "1",**
            "api_key" : apiKey
        ]

Correct me if I’m wrong somehow, but the book, on page 581 has:

“nojsoncallback”: “1”,

with a “c”.

/****************************/
With nojsoncallback": “1”,
I get: Error fetching interesting photos: invalidJSONData

With nojsoncallbak": “1”,
Get: Error fetching interesting photos: Error Domain=NSCocoaErrorDomain Code=3840 “JSON text did not start with array or object and option to allow fragments not set.” UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}

That says to me the nojsoncallback": “1”, is the way to go and I have some other error that I gotta work on?

~paul

Hey,

its strange but i did same typo, is it a co-incidence or something else, let me know please if you find some thing

Thanks,
Rajat