2012-03-16 13 views
0

私はIOS5のアプリケーションを作成し始めました。私は現在、データベースからデータを取得するためにアプリケーションが呼び出すPHP Webサービスを持っています。データベースには現在3行あり、デバッガに入ると辞書には3つのキー/値の組があります。私は値のいずれかを取得することはできません。以下の私のコード:JSONデータで埋め込まれたNSDictionaryからデータを抽出できません

NSURL *myUrl = [[NSURL alloc]initWithString:@"http://localhost/~stephen-hill9/index.php"]; 
NSData *data = [[NSData alloc] initWithContentsOfURL:myUrl]; 
NSError *error; 
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error]; 
NSLog(@"Parsed Data: %@", json); 
NSDictionary *bodyDictionary = [json objectForKey:@"Product_Desc"]; <-APP CRASHES HERE - INVALID KEY 
NSLog(@"Parsed Data: %@", bodyDictionary); 

はまた、ここでは辞書は、私は、デバッガからもらった含まれていることをデータである:

Parsed Data: (
     { 
     0 = 1; 
     1 = "Caromax 20HN B/F"; 
     2 = 51533; 
     3 = 6650; 
     4 = 1117760; 
     5 = 1067224; 
     6 = 1759741; 
     7 = 1; 
     8 = "0000-00-00 00:00:00"; 
     ID = 1; 
     "Max_Volume" = 1759741; 
     "Product_Code" = 51533; 
     "Product_Desc" = "Caromax 20HN B/F"; 
     Pumpable = 1067224; 
     Status = 1; 
     "Tank_Level" = 6650; 
     Updated = "0000-00-00 00:00:00"; 
     Volume = 1117760; 
    }, 
     { 
     0 = 2; 
     1 = "C1 Kerosine"; 
     2 = 25101; 
     3 = 1258; 
     4 = 146871; 
     5 = 111776; 
     6 = 1018590; 
     7 = 2; 
     8 = "2023-02-12 20:00:00"; 
     ID = 2; 
     "Max_Volume" = 1018590; 
     "Product_Code" = 25101; 
     "Product_Desc" = "C1 Kerosine"; 
     Pumpable = 111776; 
     Status = 2; 
     "Tank_Level" = 1258; 
     Updated = "2023-02-12 20:00:00"; 
     Volume = 146871; 
    }, 
     { 
     0 = 3; 
     1 = "Recovered Spirit"; 
     2 = 87902; 
     3 = 6069; 
     4 = 710172; 
     5 = 675078; 
     6 = 1018200; 
     7 = 1; 
     8 = "2012-03-16 00:00:00"; 
     ID = 3; 
     "Max_Volume" = 1018200; 
     "Product_Code" = 87902; 
     "Product_Desc" = "Recovered Spirit"; 
     Pumpable = 675078; 
     Status = 1; 
     "Tank_Level" = 6069; 
     Updated = "2012-03-16 00:00:00"; 
     Volume = 710172; 
    } 
) 

私は、誰かが助けることができることを望む - 私は、問題がなければなりません確信しています何か基本的なもの。あなたがここに来た「VEの何を事前に

多くのおかげで、

+0

...これはあなたの最初のオブジェクトを取得しますが、あなたのアイデアを得ますか? – giorashc

答えて

1

[OK]を

スティーブンは、辞書の配列ではなく、辞書そのものです。 このお試しください:もちろん

NSArray *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error]; 
NSDictionary *bodyDictionary = [json objectAtIndex:0]; 

をあなたの辞書からデータを抽出するにはどうすればよい

+0

あなたの答えをありがとう - 私はNSDictionaryの "objectAtIndex"メソッドを見つけることができません: - – HillInHarwich

+0

おっと...お詫び - 私はちょうど最初の辞書を変更しました - json配列とobjectAtIndexを第2辞書に抽出、それは働いています。ご協力いただき誠にありがとうございます! – HillInHarwich

+0

あなたを助けてくれた嬉しいこと:あなたが探していたものなら、答えを正しいものにすることを検討してください。 – Alladinian

関連する問題