I am parsing the XML data as the following and it is working in objective-C (I can show the 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 this topic about How to parse a JSON file in swift? but I am getting an issue that "fatal error: unexpectedly found nil while unwrapping an Optional value"
in the jsonData
line. So please where would be my 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) as NSDictionary
for parseData in jsonDict {
println(parseData)
}