0

Anil_Ambaniを検索しているときに、wikipedia api から流れるような json レスポンスを取得しました。このAPIを使用しました。私は次の応答を得た

<i>$2 = 0x071882f0 {{BLP sources|date=June 2012}}
{{Infobox person
| name             = Anil Ambani 
| image            =AnilAmbani.jpg
| image_size       = 
| caption          = Ambani in 2009
| birth_date       = {{Birth date and age|1959|6|4|df=y}}
| birth_place      = [[Mumbai]], [[Maharashtra]], [[India]]
| nationality      = Indian
| occupation       = Chairman of [[Anil Dhirubhai Ambani Group]] 
| networth         = {{loss}} [[United States dollar|$]]5.2 billion (2012)<ref         name="forbes.com">[http://www.forbes.com/profile/anil-ambani/.] Forbes.com. Retrieved April 2013.</ref> 
| residence        = Mumbai, Maharashtra, India
| alma_mater       = [[Warwick Business School]]<br />[[Wharton School of the University of Pennsylvania|The Wharton School]]
| parents          = [[Dhirubhai Ambani]]<br>Kokilaben Ambani
| brother          = [[Mukesh Ambani]]
| spouse           = [[Tina Ambani]]
| children         = 2<ref>{{cite web|url=http://www.indiatoday.com/itoday/20050221/power9.html |title=India Today 2005 Power List |publisher=Indiatoday.com |date=2005-02-21 |accessdate=2010-12-31}}</ref>
|religion         = [[Hinduism]]  
|relations        = [[Mukesh Ambani]] (Brother)
|website          = {{URL|http://www.relianceadagroup.com/ada/chairman.html|Anil Ambani}} 
|footnotes        = 
}}

誰でもデータをフィルタリングする方法を教えてもらえますか? それはNSStringです。辞書に変換できません。名前、生年月日、出生地などの値を取得する方法

4

1 に答える 1

0

最初のアプローチ:-
まず、文字列から空白と無関係な文字を削除します。
次に、次のように進みます。

NSArray *testArray = [yourString componentsSeparatedByString:@"|"];
NSString *key = [testArray objectAtIndex:0];
NSArray *values = [testArray subarrayWithRange:NSMakeRange(1, [testArray count] - 1)];
NSDictionary *dict = [NSDictionary dictionaryWithObject:values forKey:key];


また、名前、出生地などの特定のキーの値を簡単に取得できます。2 番目の

アプローチ:-

NSError *err = nil;
NSArray *arr = [NSJSONSerialization JSONObjectWithData:[yourString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:&err];


NSMutableDictionary *dict = arr[0];
    for (NSMutableDictionary *dictionary in arr) {
        // do something using dictionary
    }
于 2013-07-24T09:08:00.573 に答える