ios - Parsing data in Swift - issue -


i parsing xml data following , working in objective-c (i can show objective-c code if needed.

//update  //nsdata     response = [[nsdata alloc] initwithcontentsofurl:[nsurl urlwithstring:@"http://kalkatawi.com/jsontest.php"]];  if(response!=nil) {  nserror *parseerror = nil;  jsonarray1 = [[nsmutablearray alloc] init];  for(int i=0;i<[jsonarray count];i++) {     nsstring  * city = [[jsonarray objectatindex:i] objectforkey:@"city"];      [jsonarray1 addobject:city];      nslog(@"%@", jsonarray1); } 

my web result:

<city>1</city><city>2</city><city>3</city> 

i have read topic how parse json file in swift? getting issue "fatal error: unexpectedly found nil while unwrapping optional value" in jsondata line. please issue?

my code:

    let urlpath = "http://example.net/example/example.php"      //crash happens here     let jsondata: nsdata = nsdata.datawithcontentsoffile(urlpath, options: .datareadingmappedifsafe, error: nil)      let jsondict = nsjsonserialization.jsonobjectwithdata(jsondata, options: nil, error: &error) nsdictionary      parsedata in jsondict {          println(parsedata)     } 

edit: looks apple has not implemented nsxmldocument in swift yet. here library might parsing xml in swift: https://github.com/ndavidsson/ndhpple

if implemented, how it:

let urlpath:nsurl = nsurl(scheme:"http", host:"example.net", path:"example/example.php") var error: nserrorpointer? = nil var xml:nsxmldocument = nsxmldocument(contentsofurl: urlpath, error: error!) 

at point, xml represent nsxmldocument. https://developer.apple.com/library/prerelease/mac/documentation/cocoa/reference/foundation/classes/nsxmldocument_class/


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -