JSON のタイトルと説明の文字列に到達するのに問題があります。タブ名とカテゴリ名にはたどり着けるのですが、商品説明とタイトルにたどり着く方法がわかりません。
これが私のJSONです:
{
"tab1":
[
{
"category1Tab1":
[
{
"title":"film1",
"description": "desc1"
},
{
"title": "film2",
"description": "desc2"
}
],
"category2Tab1":
[
{
"title": "tv",
"description": "desc1"
},
{
"title": "tv2",
"description": "desc2"
}
]
}
],
"tab2":
[
{
"category1Tab2":
[
{
"title":"item1",
"description": "desc1"
},
{
"title": "item2",
"description": "desc2"
}
]
}
]
}
解析用のコードは次のとおりです。
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"json"];
NSString *contents = [NSString stringWithContentsOfFile: filePath encoding: NSUTF8StringEncoding error: nil];
SBJsonParser *jsonParser = [[SBJsonParser alloc] init];
NSMutableDictionary *json = [jsonParser objectWithString: contents];
jsonParser = nil;
for (NSString *tab in json)
{
Tab *tabObj = [[Tab alloc] init];
tabObj.title = tab;
NSDictionary *categoryDict = [[json valueForKey: tabObj.title] objectAtIndex: 0];
for (NSString *key in categoryDict)
{
Category *catObj = [[Category alloc] init];
catObj.name = key;
//Code for the items
}
}
各タイトルと説明にアクセスして、アイテムと呼ばれるカテゴリ モデル オブジェクト配列にプッシュするにはどうすればよいですか?