0

Jsonデータを含む辞書があります。その中のデータを処理できません。列挙しようとしましたが、失敗し続けます。

This is the data format I am getting back using NSLog:

2013-03-21 12:48:36.973 SaleItems[21009:c07] {
    article = "Surface's other shoe is about to drop: the full Windows 8, Intel Core-driven Surface is headed to stores in just a few weeks.";
    id = 2;
    title = "Microsoft Surface Pro hits U.S. and Canada ";
}
2013-03-21 12:48:36.974 SaleItems[21009:c07] {
    article = "Hit by growing demand for Samsung devices, the iPhone will lose smartphone market share for the current quarter, says a Citi analyst";
    id = 3;
    title = "iPhone to shed market share";
}
2013-03-21 12:48:36.974 SaleItems[21009:c07] {
    article = "The carrier says it plans to buy wireless spectrum and network assets from Atlantic Tele-Network, aka Alltel, in an effort to boost its spectrum coffers.";
    id = 4;
    title = "AT&T spends $780 million ";
}

その見た目から、配列の辞書を取り戻していることがわかります。配列とその中の要素にアクセスするにはどうすればよいですか?

4

1 に答える 1

2

記事、ID、タイトルとしてキーを持っているようです。ループ内のオブジェクトに次のようにアクセスするだけです。

* SalesItemというクラスがあり、上記のログはその各オブジェクトからのものであると想定しています。

for(SalesItem *object in SalesItem){
    NSLog(@"Article : %@",object[@"article"]);
    NSLog(@"Id : %@",object[@"id"]);
    NSLog(@"Title : %@",object[@"title"]);
}
于 2013-03-21T09:59:15.023 に答える