Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Looks like your config contents were output by <code>NSLog</code>, which results in invalid JSON hence assuming that your actual config file is a valid JSON object, following code should get you what you need:</p> <pre><code>//Don't forget to replace "configfile" with your config file name in the project NSString *configPath = [[NSBundle mainBundle] pathForResource:@"configfile" ofType:nil]; NSData *data = [[NSFileManager defaultManager] contentsAtPath:configPath]; NSDictionary *config = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil]; NSArray *ports = [config valueForKeyPath:@"main.inputs.port"]; //ports[0] is 10001 //ports[1] is 10002 </code></pre> <p>Here you can verify if your JSON is valid: <a href="http://jsonlint.com" rel="nofollow">http://jsonlint.com</a>. This is how your valid JSON confi should look like:</p> <pre><code>{ "main": { "delay": "10000", "inputs": [ { "enabled": true, "ip": "127.0.0.1", "port": 10001, "file": "c: \\abc.txt" }, { "enabled": true, "ip": "127.0.0.1", "port": 10002, "file": "c: \\myfile.txt" } ] } } </code></pre> <p>EDIT:</p> <p>I would personally use a model framework rather than just a json parser to save you from a ton of manual work that comes with built-in <code>NSJSONSerialization</code> class. Here are couple of pretty good ones:</p> <p>1) <strong>GitHub Mantle</strong> - <a href="https://github.com/MantleFramework/Mantle" rel="nofollow">https://github.com/MantleFramework/Mantle</a> I use it where ever I can. It is very well written and thought out framework but has a little bit of learning curve involved, which probably is true to any new piece of software.</p> <p>2) <strong>SBJson</strong> - <a href="https://github.com/stig/json-framework" rel="nofollow">https://github.com/stig/json-framework</a> You can use <code>SBJson</code> if you just wanna get the job done, it has been pretty popular, especially before Mantle and other frameworks became available.</p> <p>I hope it helps.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload