Parsing a JSON file using JSONKit

I am creating a fork tuning application. The plug must allow up to 12 predefined steps.

In addition, I want to allow the user to select a theme. Each theme loads a set of presets (it is not necessary to use all of them).

My configuration file will look something like this: * /


theme: "A3"
comment: "An octave below concert pitch (ie A4 440Hz)"
presets: {
    A3 220Hz=220.0
}

// http://en.wikipedia.org/wiki/Guitar_tuning
theme: "Guitar Standard Tuning"
comment:"EADGBE using 12-TET tuning"
presets: {
    E2=82.41
    A2=110.00
    D3=146.83
    G3=196.00
    B3=246.94
    E4=329.63
}

theme: "Bass Guitar Standard Tuning"
comment: "EADG using 12-TET tuning"
presets: {
    E1=41.204
    A2=55.000
    D3=73.416
    G3=97.999
}

... which must be extracted into some structure as follows:


@class Preset
{
    NSString* label;
    double freq;
}

@class Theme
{
    NSString* label;
    NSMutableArray* presets;
}

NSMutableArray* themes;

How to write a file using JSON? (I would like to create a minimal set of text for the user - how much can I get it? Can someone give me an example for the first topic?)

And how to parse it in structures using https://github.com/johnezang/JSONKit ?

+5
2

JSON, :

[
    {
        "name": "Guitar Standard Tuning",
        "comment": "EADGBE using 12-TET tuning",
        "presets": {
            "E2": "82.41",
            "A2": "110.00",
            "D3": "146.83",
            "G3": "196.00",
            "B3": "246.94",
            "E4": "329.63"
        }
    },
    {
        "name": "Bass Guitar Standard Tuning",
        "comment": "EADG using 12-TET tuning",
        "presets": {
            "E1": "41.204",
            "A1": "55.000",
            "D2": "73.416",
            "G2": "97.999"
        }
    }
]

JSONKit:

NSData* jsonData = [NSData dataWithContentsOfFile: path];
JSONDecoder* decoder = [[JSONDecoder alloc]
                             initWithParseOptions:JKParseOptionNone];
NSArray* json = [decoder objectWithData:jsonData];

json, for.

+10

, Simeon NSString. :

#import "JSONKit.h"


id parsedJSON = [myJSONString objectFromJSONString];

, , Preset Theme. , name, comment presets. NSString, (presets) ( NSString ).

+6

All Articles