2011-08-31 47 views
0

林接收来自UPX服务器JSON数组和我不能得到的值问题从JSON数组目标c得到一个值

我需要的对象“名”从“relation_data”,但我不能进入“relation_data”

这是我要做的事

NSLog(@"All of the arrays: %@", json); 
    NSDictionary *Allinfo = [json objectForKey:@"response"];//I go into "response" 
    NSLog(@"All with response array: %@", Allinfo); 
    NSDictionary *datainfo = [Allinfo objectForKey:@"data"];//i go into "data" 
    NSLog(@"Data : %@", datainfo); 

但我怎么进入“relation_data”并获得“名”的价值?

response = ( 
data =  (
         { 
        "business_data_rev" = 12; 
        "contact_set_rev" = 15; 
        currency = EUR; 
        "date_added" = "2011-08-31 12:10:59.338664+02"; 
        "date_invoiced" = "2011-08-31 12:10:59.338664+02"; 
        "date_modified" = "2011-08-31 12:11:04.45442+02"; 
        "date_paid" = "2011-08-31 12:10:59.408335+02"; 
        description = ""; 
        id = 104; 
        name = "Invoice #104"; 
        "person_rev" = 12; 
        realid = 104; 
        "relation_data" =    { 
         id = 12; 
         iscreditor = 0; 
         isdebitor = 1; 
         isprivate = 0; 
         name = "Emre."; 
         "subaccount_id" = 9; 
        }; 
     ) 

回答

3

试试这个

[dataInfo valueForKeyPath:@"relation_data.name"]; 
+0

嗯,如果我这样做,我得到在1个变量的字符串,例如所有的名字(104条记录),我怎样才能得到它的1 1? – Oblieapps

+2

尝试'[[dataInfo objectAtIndex:0] valueForKeyPath:@“relation_data.name”]' – Eimantas

+0

ahh like that!ty ty mate! – Oblieapps