-2

Objective-C を使用して json を解析するのに助けが必要です

これは私のjsonです:

{
    "days": [
        {
            "reference": "13L6-A67-1",
            "period": "",
            "dayinit": "4",
            "hourinit": "9",
            "minuteinit": "30",
            "dayend": "4",
            "hourend": "10",
            "minuteend": "30",
            "totalattendance": "5",
            "currentattendance": "5",
            "teacher_surname": "jones",
            "teacher_forenames": "Carol",
            "room": "C109"
        },
        {
            "reference": "13NAPUSD-A1",
            "period": "",
            "dayinit": "3",
            "hourinit": "10",
            "minuteinit": "45",
            "dayend": "3",
            "hourend": "11",
            "minuteend": "45",
            "totalattendance": "3",
            "currentattendance": "3",
            "teacher_surname": "Carol",
            "teacher_forenames": "Nicola",
            "room": "M139"
        },
        {
            "reference": "13NASUWO-X1",
            "period": "",
            "dayinit": "3",
            "hourinit": "14",
            "minuteinit": "40",
            "dayend": "3",
            "hourend": "15",
            "minuteend": "5",
            "totalattendance": "0",
            "currentattendance": "0",
            "teacher_surname": "",
            "teacher_forenames": "",
            "room": ""
        },
        {
            "reference": "13NASUWO-X1",
            "period": "",
            "dayinit": "5",
            "hourinit": "13",
            "minuteinit": "35",
            "dayend": "5",
            "hourend": "14",
            "minuteend": "0",
            "totalattendance": "0",
            "currentattendance": "0",
            "teacher_surname": "",
            "teacher_forenames": "",
            "room": ""
        }]}

次に、さまざまな「Dayinit」キーの個別の配列にフィルターする必要があります。私はこれをどこから始めるべきかわかりません。

これまでのところ、jsonの解析に関するYouTubeの重要なビデオしか見つけていませんが、解析後にデータをフィルタリングする方法を示しているものはありません

4

3 に答える 3

0

そのようにjsonを解析できます

  NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:nil];
  NSMutableArray *jsonParseArray = [[NSMutableArray alloc] initWithArray:[jsonDic objectForKey:@"days"]];

次に、配列内の各要素objectAtIndex:を NSDictionary に取得します。

NSDictionary *selectedDic = [jsonParseArray objectAtIndex:0];

objectForKeyキーを使用するだけで辞書の値を取得できます

        "reference": 
        "period": 
        "dayinit": 
        "hourinit": 
        "minuteinit": 
        "dayend": 
        "hourend": 
        "minuteend": 
        "totalattendance":
        "currentattendance":
        "teacher_surname": 
        "teacher_forenames": 
        "room": 
于 2013-10-11T07:02:24.677 に答える
0

`Iteration through the Json Value. を使用して取得できます。

参考までに:

ContentDict = [NSJSONSerialization JSONObjectWithData:returnData options:0 error:nil];

days = [ContentDict objectForKey:@"days"];
    // 3. iterate the array; each element is a dictionary...
                    for (NSDictionary *lesson in days)
                    {

                        NSString *content = [lesson objectForKey:@"reference"];
                        NSString *content2 = [lesson objectForKey:@"dayinit"]; 
                        // ........
                           ........
                           .......

                        NSLog(@"Reference  : %@", content);

                    } 
于 2013-10-11T06:57:54.180 に答える