0

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.

Steaphann
  • 2,797
  • 6
  • 50
  • 109

2 Answers2

0

QuickDialog doesn't currently do what you're trying to do. The initWithJSONFile method takes either a string as the name of the local file, or an object structure with the data (which should follow the JSON format, like if you read the file yourself in your code. The dataParameter needs to be passed in the method, which can be just an empty dictionary.

For now, you'll have to first download the file yourself, and then parse it and pass it to that method, instead of just the NSURL.

I've been thinking of adding this to the project directly, but from experience, it seems like every application will need to do things in a different way (like, should we show a loading screen or not, should we show a message if theres an error or not, etc), so having it in the app directly would't help a lot of people.

Feel free to jump on the google group for QuickDialog to discuss this with others!

Eduardo Scoz
  • 24,653
  • 6
  • 47
  • 62
  • I've added a custom function to the library which takes an NSURL, and that did the trick for me. I will post the function as an answer. – Steaphann Nov 09 '12 at 07:57
0

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;
}
Steaphann
  • 2,797
  • 6
  • 50
  • 109