文字列にサブオブジェクトを持つ json オブジェクトを処理する方法。ここに例があります
[{"_id":"1","タイトル":"パイナップル","説明":"ドール パイナップル","アイコン":"icon.png","アクション":{"ACTION_PHOTO":"coupon.png ", "ACTION_LINK":"google.com"}}]
2番目のjson「アクション」をどのように解析しますか?
文字列にサブオブジェクトを持つ json オブジェクトを処理する方法。ここに例があります
[{"_id":"1","タイトル":"パイナップル","説明":"ドール パイナップル","アイコン":"icon.png","アクション":{"ACTION_PHOTO":"coupon.png ", "ACTION_LINK":"google.com"}}]
2番目のjson「アクション」をどのように解析しますか?
ここにあるのは辞書の配列 (1 エントリ) で、最上位の辞書のエントリの 1 つも辞書です。したがって、それを解析するには次のようなものがあるかもしれません:
NSError *e = nil;
NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error: &e];
if (jsonArray) {
NSDictionary *dictActions;
for (NSDictionary *dict in jsonArray) {
dictActions = [dict objectForKey:@"Actions"];
NSLog(@"The action link is: %@", [dictActions objectForKey@"ACTION_LINK"]);
}
} else {
NSLog(@"Error parsing JSON: %@", [e localizedDescription]);
}