0

文字列にサブオブジェクトを持つ json オブジェクトを処理する方法。ここに例があります

[{"_id":"1","タイトル":"パイナップル","説明":"ドール パイナップル","アイコン":"icon.png","アクション":{"ACTION_PHOTO":"coupon.png ", "ACTION_LINK":"google.com"}}]

2番目のjson「アクション」をどのように解析しますか?

4

1 に答える 1

3

ここにあるのは辞書の配列 (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]);
}
于 2013-02-04T23:31:44.327 に答える