2017-03-01 59 views
1

我认为这是一个数组,我打字如何解析JSON的这个样本

_price1=[venues valueForKey:@"price_total”]; 

我得到这个的输出,我有望拿到6作为计数时,我输入 这

NSLog(@"%lu", (unsigned long)_price1.count); 

事实是,我得到1作为计数的输出。

(
    (
    772, 
    912, 
    912, 
    912, 
    912, 
    935 
) 
) 

我怀疑是我怎么能解析它,以便输出中是array.Do告诉我)的含义([本括号]当JSON是考虑。

我的代码是

好我的代码是:

-(void)initialize{ 

id venues = [[_json valueForKey:@"hotels_prices"]valueForKey:@"agent_prices”]; 

_price1=[venues valueForKey:@"price_total"];//global array... 
NSLog(@"%@", _price1); 
NSLog(@"%lu", (unsigned long)_price1.count);} 

JSON是:这是根据代码

(

     (

     { 

     id = 146; 
     "price_per_room_night" = 158; 
     "price_total" = 944; 
     "room_offers" =    (  //problem 
          { 
       available = 0; 
       "meal_plan" = "Room only"; 
       "policy_dto" =      { 
       }; 
       rooms =      (
              { 
         adults = 0; 
         children = 0; 
         type = "Double room"; 
         "type_id" = "ROOMTYPE_DOUBLE"; 
        } 
       );//problem 
      }, 

//看(ID场馆),其括号() ;是问题

+0

我们确实需要看到输入内容以说明为什么代码不起作用。显示你的代码也不会伤害! – wander

+0

是啊,欢迎来到stackoverflow :)确保总是重新读你的问题,并把自己放在你完全没有语境(我们的位置)的地方。如果你没有足够的信息,那意味着你需要编辑你的问题。现在,您需要向我们展示您正在谈论的json以及您如何使用它。 –

+0

好吧,我的代码是 - (void)initialize {} {}} {}}}};}}}; _price1 = [场地valueForKey:@“price_total”]; //全局数组... NSLog(@“%@”,_price1); NSLog(@“%lu”,(unsigned long)_price1.count); } – Kaustubh

回答

0

是的!我马上告诉括号(),我得到了答案。应被视为一个数组

id venues = [[_json valueForKey:@"hotels_prices"]valueForKey:@"agent_prices”]; 

给出了上述的json,但如果我想要得到的膳食计划

NSArray*meal=[[_json valueForKey:@"room_offers"]valueForKey:@"meal_plan”]; 

然后我可以输入:

NSArray*meal_plan=[meal objectAtIndex:0];//or any other index not beyond the array limit.. 

我们可以得到所需的输出和 阵列餐可以正常解析。