I am using the QuickDialog library, which is awesome! I managed so far to place a json file into my project and display it. But know I want to read it from a webservice. But the function takes a string. You can see the function over here.
- (QRootElement *)initWithJSONFile:(NSString *)jsonPath {
self = [self initWithJSONFile:jsonPath andData:nil];
return self;
}
What I do is the following.
[sectionSamples addElement:[[QRootElement alloc] initWithJSONFile:@"loginform"]];
[sectionSamples addElement:[[QRootElement alloc] initWithJSONFile:[NSURL URLWithString:[NSString stringWithFormat:@"%@",@"http://192.168.0.102/testWeb/callback2.json"]]]];
Like you can see my first element just loads a json (loginform) in that is located somewhere in my project. But when I want the second form (callback2.json) to load in. It says dataparameter is nil .
When I browse to the url in my browser it is correctly displaying it.
Can anybody help me?
Kind regards.
Ok, so the solution was to maken an override of the function initWithJsonFile, which takes an NSURL as parameter.
- (QRootElement *)initWithJSONURL:(NSURL *)jsonPath andData:(id)data{
Class JSONSerialization = [QRootElement JSONParserClass];
NSAssert(JSONSerialization != NULL, @"No JSON serializer available!");
NSError *jsonParsingError = nil;
//NSString *filePath = [[NSBundle mainBundle] pathForResource:jsonPath ofType:@"json"];
NSDictionary *jsonRoot = [JSONSerialization JSONObjectWithData:[NSData dataWithContentsOfURL:jsonPath] options:0 error:&jsonParsingError];
self = [self initWithJSON:jsonRoot andData:data];
return self;
}