ios - Trouble Getting JSON Array -


i'm having issue getting json array using swift.

func getbenefitjson() -> [anyobject] {         let urlstring = string("https://www.kyfb.com/kyfb/includes/themes/codeblue/display_objects/custom/remote/webservices/services.cfc?method=getmemberbenefits")         let url = url(string: urlstring!)         var data = data()         {             data = try data(contentsof: url!)         } catch {          }          print("url data: \(data)")          {             let json = try jsonserialization.jsonobject(with: data, options: jsonserialization.readingoptions()) as! [anyobject]             print("json: \(json)")             return json         } catch {             print("could not json")             return []         }     } 

i data url empty array returned. doing wrong?

url data: 42769 bytes not json 

below response of json

[{"image":"https://cdn.kyfb.com/kyfb/cache/file/70162997-e06b-e9b6-88514280ca8397cc_medium.jpg","description":"","link":"https://www.kyfb.com/insurance/insurance-products/","name":"kfb insurance","children":[]}, ...] 

below error

userinfo={nsdebugdescription=json text did not start array or object , option allow fragments not set.} 

i've validated response url @ jsonlint.com

url data string:

<wddxpacket version='1.0'><header/><data><string>[{"image":"https://cdn.kyfb.com/kyfb/cache/file/70162997-e06b-e9b6-88514280ca8397cc_medium.jpg","description":"","link":"https://www.kyfb.com/insurance/insurance-products/","name":"kfb insurance","children":[]}, ...]</string></data></wddxpacket>) 

i tested code , working if top level of json array. json want read not array dictionary.

to read dictionary need change return type [anyobject] [string:anyobject] , other occurrences of type.

nevertheless, recommend use swiftyjson working json in swift.


Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -