0

私はiOSとJSONの解析が初めてで、次のようなJSONデータを取得しています。

 [
     {
         "id":3,
         "name":"SCORM 0",
         "visible":1,
         "summary":"",
         "summaryformat":1,
         "modules":[
                    {
                        "id":1,
                        "url":"http:\/view.php?id=1",
                        "name":"Course01",
                        "visible":1,
                        "modicon":"http:\theme\/image.php\/standard\/scorm\/1378190687\/icon",
                        "modname":"scorm",
                        "modplural":"SCORM packages",
                        "indent":0
                    },
                    {
                        "id":2,
                        "url":"http:\/\/192.168.4.196\/moodle\/mod\/forum\/view.php?id=2",
                        "name":"News forum",
                        "visible":1,
                        "modicon":"http:\//image.php\/standard\/forum\/1378190687\/icon",
                        "modname":"settle",
                        "modplural":"Forums",
                        "indent":0
                    }
                    ]
     },
     {
         "id":2,
         "url":"http:\/\/view.php?id=2",
         "name":"News forum",
         "visible":1,
         "modicon":"http:\/\theme\/image.php\/standard\/forum\/1378190687\/icon",
         "modname":"forum",
         "modplural":"Forums",
         "indent":0
     }
     ]

データを分離して"modname" != "forum"、それぞれのデータを配列に格納する必要があります。

ヘルプとソリューションをいただければ幸いです。

4

2 に答える 2

3
NSMutableArray *jsonArray = [[NSJSONSerialization JSONObjectWithData: data options: NSJSONReadingMutableContainers error: &e] mutableCopy];

jsonArray = [jsonArray filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
    return ![evaluatedObject[@"modname"] isEqualToString:@"forum"];
}];

これはあなたができることのスケッチです

于 2013-09-06T08:53:35.557 に答える
1
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingMutableContainers error: &error];

    NSLog(@"%@",json);

    NSLog(@"%@",delegate.firstArray);

    NSArray * responseArr = json[@"Deviceinfo"];

    for(NSDictionary * dict in responseArr)
    {
        [delegate.firstArray addObject:[dict valueForKey:@"id"]];
        [delegate.secondArray addObject:[dict valueForKey:@"name"]];
        [delegate.thirdArray addObject:[dict valueForKey:@"visible"]];
        [delegate.fourthArray addObject:[dict valueForKey:@"summery"]];

    }

ここで、すべてのデータはキーに従って配置されます

于 2013-09-06T09:14:12.597 に答える